Reference no: EM132260993
This the question
Using the table below, write a program that presents these seven proverbs one at a time and asks the user to evaluate them as true or false. The program should then tell the user how many questions were answered correctly, and display one of the following evaluations: Perfect (all seven answers correct), Excellent (5 or 6 correct), You might want to consider taking Psychology 101 (less than 5 correct).
Proverb Truth Value
The squeaky wheel gets the grease True
Cry and you cry alone True
Opposites attract False
Spare the rod and spoil the child False
Actions speak louder than words True
Familiarity breeds contempt False
Marry in haste, repent at leisure True
You must utilize at least two switch statements and three functions (including main) in your solution.
One solution could look like this, yours might be different:
main
switch statement to present each of the proverbs in order
function call to func1 to process the answers, returning either true or false
accumulate correct answer total
function call to func2 to output the results, pass in total correct
func1
ask user for answer, return true or false
func2
switch statement to output results
7 correct == perfect
5 or 6 correct == excellent
< 5 correct == you should take Psychology 101
I have problem in my coding. I do not why I'm keep making a mistake. This is my code. Please someone explain to me why I'm doing wrong. Can someone explain to me step by step?
#include <iostream>
#include <string>
using namespace std;
bool provout (int i);
void finalout (int correct);
int main (void)
{
string prov1 = "The squeaky wheel gets the grease";
string prov2 = "Cry and you cry alone";
string prov3 = "Opposites attract";
string prov4 = "Spare the rod and spoil the child";
string prov5 = "Actions speak louder than words";
string prov6 = "Familiarity breeds contempt";
string prov7 = "Marry in haste, repent at leisure";
bool ans = 0;
int total = 0;
for (int i = 0; i < 7; i++)
{
switch (i)
{
case 0 :
{
cout << prov1 << endl;
ans = provout (i);
break;
}
case 1 :
{
cout << prov2 << endl;
ans = provout (i);
break;
}
case 2 :
{
cout << prov3 << endl;
ans = provout (i);
break;
}
case 3 :
{
cout << prov4 << endl;
ans = provout (i);
break;
}
case 4 :
{
cout << prov5 << endl;
ans = provout (i);
break;
}
case 5 :
{
cout << prov6 << endl;
ans = provout (i);
break;
}
case 6 :
{
cout << prov7 << endl;
ans = provout (i);
break;
}
}
total = total + ans;
}
finalout (total);
return 0;
}
bool provout (int i)
{
bool ans = 0;
bool ok = 0;
cout << "Please answer 1 for True or 0 for False ";
cin >> ans;
switch (i)
{
case 0 :
{
if (ans == 1)
ok = 1;
else
ok = 0;
break;
}
case 1 :
{
if (ans == 1)
ok = 1;
else
ok = 0;
}
case 2 :
{
if (ans == 0)
ok = 1;
else
ok = 0;
break;
}
case 3 :
{
if (ans == 0)
ok = 1;
else
ok = 0;
break;
}
case 4 :
{
if (ans == 1)
ok = 1;
else
ok = 0;
break;
}
case 5 :
{
if (ans == 0)
ok = 1;
else
ok = 0;
break;
}
case 6 :
{
if (ans == 1)
ok = 1;
}
}
return ok;
}
void finalout (int correct)
{
switch (correct)
{
case 7 :
{
cout << "Excellent!n";
break;
}
}
}