![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 3
Rep Power: 0
![]() |
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
string username;
char again;
int answer;
cout<<"text\n";
cout<<"text\n";
cout<<"text\n\n";
Sleep(5000);
cout<<"enter a username and press enter:";
cout<<"\nUsername: ";
cin>>username;
Sleep(500);
cout<<"\n\nConnecting, please wait...";
Sleep(1000);
cout<<"\n\ntext";
Sleep(1500);
cout<<"\n.";
Sleep(500);
cout<<".";
Sleep(500);
cout<<".";
Sleep(1500);
cout<<"\ntext";
Sleep(1000);
top:
cout<<"\n\ntext";
Sleep(3000);
cout<<"\ntext";
Sleep(1000);
cout<<"\ntext";
Sleep(500);
cout<<"\n\enter some text and press enter: ";
cin.get();
Sleep(6000);
cout<<"\n\ntext";
Sleep(3000);
cout<<"\ntext";
Sleep(3000);
cout<<"\nenter a number between 1 and 3, and press enter: ";
cin>>answer;
if (answer==1)
{
cout<<"\ntext\n";
Sleep(1500);
cout<<"\ntext";
Sleep(4000);
cout<<"\n\nwould you like to go again? <y/n>: ";
cin>>again;
if (again=='y') {
goto top; }
else {
cout<<"\n\nThanks for using my program! Press enter to exit.";
cin.get();
}
}
else if (answer==2)
{
cout<<"\njtext\n";
Sleep(1500);
cout<<"\ntext";
Sleep(1500);
cout<<"\ntext";
Sleep(4000);
cout<<"would you like to go again? <y/n> ";
cin>>again;
if (again=='y') {
goto top; }
else {
cout<<"\n\nThanks for using my program! Press enter to exit.";
cin.get();
}
}
else if (answer==3)
{
cout<<"\ntext\n";
Sleep(1500);
cout<<"\ntext\n";
Sleep(1500);
cout<<"\ntext\n\n";
Sleep(4000);
cout<<"Would you like to go again? <y/n> ";
cin>>again;
if (again=='y') {
goto top; }
else {
cout<<"Thanks for using my program! Press enter to exit.";
cin.get();
}
}
else
{
cout<<"\n\nOpps! You didn't enter a number from 1-3! Press enter to try it again.";
cin.get();
goto top;
}
}The program compiles/builds without error, but whenever the program reaches the "enter a number between 1-3" part, it doesn't stop, and doesn't allow any input. It just skips the cin>> and goes directly to the else() statement at the bottom. It skips the cin.get() at the bottom too, and goes directly to the "goto top;" line. I've tried numerous things to fix it, but nothing works. Any help would be appreciated. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
Why not replace the cin.get()?
string text; cout<<"\n\enter some text and press enter: "; // cin.get(); // FIX: cin >> text; Also, try to use gotos as a last of last resorts.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|