This code is for class. It is supposed to ask the user if they want advice and then provide them with a random cliche sentence. The program runs, but even if the user inputs yes the program returns 0. (We were instructed to use a global array)
#include <iostream>
#include <string>
#include <cstdlib>
usingnamespace std;
string cliche[10] =
{
"Try to be a rainbow in someone's cloud.",
"Never miss a good chance to shut up.",
"Here's some advice. Stay alive.",
"Never ruin an apology with an excuse.",
"Don't ever take a fence down until you know why it was put up.",
"Write with the door closed, rewrite with the door open.",
"Always speak politely to an enraged dragon.",
"A wise man gets more use from his enemies than a fool from his friends.",
"Don't try to solve serious matters in the middle of the night.",
"Only boring people get bored.",
};
string advice()
{
constint a = rand() %10 + 0;
string adv = cliche[a];
return adv;
}
int main()
{
bool answer = true;
string randAdv;
string response;
while (answer == true)
{
cout << "Would you like some advice?" << endl;
cin >> answer;
if (response == "yes")
{
randAdv = advice();
cout << randAdv;
}
else
answer = false;
}
return 0;
}