Goodmorning, afternoon, evening and night ;)
I have a question. I am following the Jumping into C++ course of Alex Allain.
I worked on chapter 5, problem 7.
This is the problem:
Write a program that provides the option of tallying up the results of a poll with 3 possible
values. The first input to the program is the poll question; the next three inputs are the possible
answers. The first answer is indicated by 1, the second by 2, the third by 3. The answers are
tallied until a 0 is entered. The program should then show the results of the poll—try making a
bar graph that shows the results properly scaled to fit on your screen no matter how many results were entered.
Do you think that this program can be a solution? If you have better suggestions,please let me know..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
int main()
{
int pollAnswer;
int pollAnswer01=0;
int pollAnswer02=0;
int pollAnswer03=0;
int pollEnteredPeople=0;
cout << "Choose one of the four options or press 0 to quit: " << endl;
cout << "1. I am amazing: " << endl;
cout << "2. I am great: " << endl;
cout << "3. I am fantastic: " << endl;
cin >> pollAnswer;
while(pollAnswer!=0)
{
pollEnteredPeople++;
if(pollAnswer == 1)
{
pollAnswer01++;
cin >> pollAnswer;
}
else if(pollAnswer == 2)
{
pollAnswer02++;
cin >> pollAnswer;
}
else if(pollAnswer == 3)
{
pollAnswer03++;
cin >> pollAnswer;
}
else if (pollAnswer >= 4)
{
cout << "You did not enter the right number! Program quitting...\n \n";
break;
}
}
cout << "The number of people entered is: " << pollEnteredPeople << endl;
cout << "nr 1 has: " << pollAnswer01 << " entries" << endl;
cout << "nr 2 has: " << pollAnswer02 << " entries" << endl;
cout << "nr 3 has: " << pollAnswer03 << " entries" << endl;
cout << "\n \nBar Graph: " << endl;
cout << "Nr.01: " << setw(pollAnswer01+1) << setfill('*') << '\n' ;
cout << "Nr.02: " << setw(pollAnswer02+1) << setfill('*') << '\n';
cout << "Nr.03: " << setw(pollAnswer03+1) << setfill('*') << '\n';
return 0;
}
|