Problem No#11 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis
/// Problem Set 3. Mobile Service Provider - Part 2
#include <iostream>
using namespace std;
int main()
{
char correct_ans[20] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
char user_ans[20];
int n_correct_ans = 0, n_wrong_ans = 0;
cout << "Enter the answer for each of the questions:- " << endl;
for ( int i = 0; i < 20; i++ )
{
cout << "Question NO # " << i + 1 << endl;
for ( int j = 0; j < 1; j++ )
{
cout << "Answer : ";
cin >> user_ans[i];
if ( cin.fail() )
{
return 0;
}
}
}
for ( int i = 0; i < 20; i++ )
{
if ( correct_ans[i] == user_ans[i] )
{
n_correct_ans = n_correct_ans + 1;
}
}
n_wrong_ans = 20 - n_correct_ans;
cout << "Number of correctly answered questions : " << n_correct_ans << endl;
cout << "Number of wrongly answored questions : " << n_wrong_ans << endl;
}
/// Code by Asad Ali and officially posted on padacode.blogspot.com
#include <iostream>
using namespace std;
int main()
{
char correct_ans[20] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
char user_ans[20];
int n_correct_ans = 0, n_wrong_ans = 0;
cout << "Enter the answer for each of the questions:- " << endl;
for ( int i = 0; i < 20; i++ )
{
cout << "Question NO # " << i + 1 << endl;
for ( int j = 0; j < 1; j++ )
{
cout << "Answer : ";
cin >> user_ans[i];
if ( cin.fail() )
{
return 0;
}
}
}
for ( int i = 0; i < 20; i++ )
{
if ( correct_ans[i] == user_ans[i] )
{
n_correct_ans = n_correct_ans + 1;
}
}
n_wrong_ans = 20 - n_correct_ans;
cout << "Number of correctly answered questions : " << n_correct_ans << endl;
cout << "Number of wrongly answored questions : " << n_wrong_ans << endl;
}
/// Code by Asad Ali and officially posted on padacode.blogspot.com
Please help me improve my work by letting me know about mistakes (if any) I mad in the project given above, by commenting on the particular post.
0 comments:
Post a Comment
Thanks for visiting my Blog.
Have any problem, feel free to contact us via Email: asadalipkp9@gmail.com
Have a nice day!