cout<<"\nEnter 'y' to start the game enter 'n' to exit";
cout<<"\n";
cin>>start;
if (start=='y')
{
cout<<"\nyou've just woke up";
cout<<"\nyou still feel sleepy";
cout<<"\nWhat should you do first?";
cout<<"\nEnter 'b' to brush your teeth and 'a' to eat your breakfast";
cout<<"\n";
cin>>choice1;
if (choice1=='a');
{
cout<<"\nyou've decided to eat your breakfast first";
}
elseif (choice1=='b'); ///here's where im having the problem misplaced else
{
cout<<"\nyou've decided to brush your teeth first";
}
}
elseif(start=='n')
{
getch();
return 0;
}
i keep getting misplaced else error
and 1 more question how can i put a loop like this:
output is like this:
Enter y to start the game
sdadadada
wrong input try again.
y
#include <iostream>
usingnamespace std;
int main()
{
char start;
char choice1;
cout << "Enter 'y' to start the game enter 'n' to exit: ";
cin >> start;
start = tolower(start);
if (start == 'y')
{
cout << "\nyou've just woke up";
cout << "\nyou still feel sleepy";
cout << "\nWhat should you do first?";
cout << "\nEnter 'b' to brush your teeth and 'a' to eat your breakfast: ";
cin >> choice1;
choice1 = tolower(choice1);
if (choice1=='a')
{
cout << "\nyou've decided to eat your breakfast first\n";
}
elseif (choice1 == 'b')
{
cout << "\nyou've decided to brush your teeth first\n";
}
}
return 0;
}
Enter 'y' to start the game enter 'n' to exit: y
you've just woke up
you still feel sleepy
What should you do first?
Enter 'b' to brush your teeth and 'a' to eat your breakfast: b
you've decided to brush your teeth first