For the context, I'm coding a quiz in C++, and I want to count correct answers by counting how many times does a string string yes = "Correct answer"
show up during the whole program.
eg.
#include <iostream>
using namespace std;
int main (void)
{
char answer, answer1;
string yes = "Correct";
string no = "Incorrect";
cout<<"1. When was Macintosh II released?"<<endl;
cout<<"a) 1985"<<endl;
cout<<"b) 1989"<<endl;
cout<<"c) 1987"<<endl;
cout<<"Answer: ";
cin>>answer;
if (answer == 'c') cout<<yes<<endl;
else cout<<no<<endl;
cout<<"2. Who created the Linux Kernel?"<<endl;
cout<<"a) Dennis Ritchie"<<endl;
cout<<"b) Linus Torvalds"<<endl;
cout<<"c) Richard Stallman"<<endl;
cout<<"Answer: ";
cin>>answer1;
if (answer1 == 'b') cout<<yes<<endl;
else cout<<no<<endl;
return 0;
}
And now, I want to count how many times does string "yes" show up in the whole program, as that would also count how many questions did the user answer correctly.
I'm new to C++ and I'm trying to learn. Thanks in advance.