Answer to Question #346472 in C++ for Wasfa

Question #346472

Jonathan is competing to be the class CR on a voting basis. Write a program to help count the number of positive and negative votes he received. The program should terminate if a student enters 0 instead of n or p.



Sample:



Enter your choice(p/n): p

Enter your choice(p/n): p

Enter your choice(p/n): n

Enter your choice(p/n): n

Enter your choice(p/n): p

Enter your choice(p/n): 0

The positive votes are: 3

The negative votes are: 2


1
Expert's answer
2022-05-30T15:05:55-0400
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n = 0; int p = 0; string s;
	do
	{
		std::cout << "Enter your choice(p/n): ";
		std::cin >> s;
		if (s == "p")
			p = p + 1;
		else if (s == "n")
			n = n + 1;
	} while (s != "0");
	std::cout << "The positive votes are:" << p << "\n";
	std::cout << "The negative votes are:" << n;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS