#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string ans, name;
cout << "Hello what is your name" << endl;
cin >> name;
cout << "Nice to meet your " << name << endl;
cout << "How is your day " << name << endl;
cin >> ans;
// if (ans.eguals("good"))
if (ans == "good")
{
cout << "Thats good, enjoy the rest of your day" << endl;
}
// if (ans.equals("fine"))
elseif (ans == "fine")
{
cout << "Just fine not good" << endl;
}
// if (ans.equals("bad"))
elseif (ans == "bad")
{
cout << "Thats too bad, i hope you have a better day tomarrow" << endl;
}
//if (ans.equals("great"))
elseif (ans == "great")
{
cout << "thats awesome to hear" << endl;
}
//if (ans.equals("terible"))
elseif (ans == "terible")
{
cout << "thats terible to here, im sorry" << endl;
}
else
{
cout << "sorry thats none of the choices try good, fine, bad, great, or terible, thank you" << endl;
}
return 0;
}
you can place continue;/break;
your code will be like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
...
while(true) //infinite loop
{
cout << "How is your day " << name << endl;
cin >> ans;
// if (ans.eguals("good"))
if (ans == "good")
{
cout << "Thats good, enjoy the rest of your day" << endl;
break; //here it will exit the loop the same for all the else if
}
...
else
{
cout << "sorry thats none of the choices try good, fine, bad, great, or terible, thank you" << endl;
continue; //will reloop (test the condition and since it's true reloop)
}
}
P.S.: in line 38 you mistyped hear
Edit: or you can do like Gkneeus told you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
...
int tryagain=1; //or bool
while(tryagain) //infinite loop
{
tryagain=0;
cout << "How is your day " << name << endl;
cin >> ans;
// if (ans.eguals("good"))
if (ans == "good")
{
cout << "Thats good, enjoy the rest of your day" << endl;
}
...
else
{
cout << "sorry thats none of the choices try good, fine, bad, great, or terible, thank you" << endl;
tryagain=1;
}
}