Write a program in C++ that present the following proverbs one at a time and pro
ID: 3785836 • Letter: W
Question
Write a program in C++ that present the following proverbs one at a time and promote 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 correct), Excellent (5 or 6 correct), Good (3 or 4 correct), Poor (0 to 2 correct).
Proverb
Truth Value
The squeaky wheel gets the grease.
True
Cry and you cry alone.
True
Opposite attract.
False
Spare the rod and spoil the child.
False
Actions speak louder than words.
True
Familiarity breeds contempt.
False
Marry in house, repent at leisure.
True
Proverb
Truth Value
The squeaky wheel gets the grease.
True
Cry and you cry alone.
True
Opposite attract.
False
Spare the rod and spoil the child.
False
Actions speak louder than words.
True
Familiarity breeds contempt.
False
Marry in house, repent at leisure.
True
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
string proverbs[] = {"The squeaky wheel gets the grease.","Cry and you cry alone.","Opposite attract.","Spare the rod and spoil the child.","Actions speak louder than words.","Familiarity breeds contempt.","Marry in house, repent at leisure."};
string correctAnswers[] = {"true", "true", "false", "false", "true", "false", "true"};
string userAnswers[7];
for(int i=0; i<7; i++){
cout<<proverbs[i]<<endl;
cout<<"Enter your answer: ";
cin >> userAnswers[i] ;
}
int totalCorrectAnswers = 0;
for(int i=0; i<7; i++){
if(correctAnswers[i] == userAnswers[i]){
totalCorrectAnswers++;
}
}
if(totalCorrectAnswers == 7){
cout<<"Perfect"<<endl;
}
else if(totalCorrectAnswers == 5 || totalCorrectAnswers == 6){
cout<<"Excellent"<<endl;
}
else if(totalCorrectAnswers == 3 || totalCorrectAnswers == 4){
cout<<"Good"<<endl;
}
else{
cout<<"Poor"<<endl;
}
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
The squeaky wheel gets the grease.
Enter your answer: true
Cry and you cry alone.
Enter your answer: false
Opposite attract.
Enter your answer: false
Spare the rod and spoil the child.
Enter your answer: true
Actions speak louder than words.
Enter your answer: true
Familiarity breeds contempt.
Enter your answer: false
Marry in house, repent at leisure.
Enter your answer: false
Good
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.