-
a big problem
can any1 tell me wut's the problem of this code:
#include <iostream.h>
int main()
{
int choice;
cout<<"Please choose: \n";
cout<<"1.ID program\n";
cout<<"2.2nd program\n";
cout<<"3.Quit\n";
cout<<" I Choose:";
cin>>choice;
if(choice==1)
{
cout<<"ok lets start!\n";
cout<<"Welcome to shady's first c++ program\n";
cout<<"wut's ur name?\n";
char name[50],action[50];
cin.getline (name, sizeof (name));
cout<<"Welcome "<<name <<"\n";
cout<<"wut do u wanna do? \n";
cin.getline (action, sizeof (action));
cout<<"no u can't "<<action <<"\n";
}
if(choice==2)
{
cout<<"ok lets start!\n";
cout<<"Welcome to shady's second c++ program\n";
char name[90];
cout<<"wut's ur name?\n";
cin.getline(name, sizeof (name));
cout<<"wut's your gender? \n";
char gender[90];
cin.getline(gender, sizeof (gender));
cout<<"wut's ur birthdate?\n";
char birthdate[90];
cin.getline(birthdate, sizeof (birthdate));
cout<<"Your name: "<<name <<"\n";
cout<<"Your gender: "<<gender <<"\n";
cout<<"Your birthdate: "<<birthdate <<"\n";
}
if (choice==3)
{
cout<<"Byebye";
}
else
{
cout<<"This is not an option";
}
return 0;
}
-
1st, use code tags and indent. makes code easier to read.
2nd, use endl at the end of your cout statements, it flushes the buffer and causes a "\n" internally.
3rd, your ifs on 2 and 3 should be "else if"
4th, don't you want to loop and do the menu again if you aren't choosing 3?
-
You will also need to add cin.ignore() after cin>>choice. It will get rid of the return at the end of the string, so your first getline in the IF (whichever is executed) won't be empty.
-
What exactly are you having problems with?