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
#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;
}
Comments
Leave a comment