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 65 66
|
#include<iostream>
#include<string>
using namespace std;
int main(){
int numCorrect = 0;
int numWrong = 0;
const int ARRAY_LENGTH = 7; //This is the number of questions and answers you have.
string userAnswer;
string question[ARRAY_LENGTH] = {
//chapter 2 and 3
"What is ESD?",
"What is EMI?",
"What is RFI?",
"In alphabetical order, What are the six major types\n of PC connections?",
"What term describes the end of a cable that goes into a port?",
"What term describes a hole or slot that accepts a plug?",
"What term is an alternative descriptor of a port?" };
string answer[ARRAY_LENGTH] = {
//chapters 3 and 2
"Electrostatic Discharge",
"Electromagnetic Interference",
"Radio Frequency Interference",
"audio, DB, DIN, FireWire, RJ, USB",
"plug",
"port",
"jack" };
for(int i = 0; i <= ARRAY_LENGTH; i++) //Same as the while loop but a little cleaner.
{
cout<< "Answered correctly: " << numCorrect << " \t Answered wrong: " << numWrong << endl; //Display how many you got right and how many you got wrong.
cout << "Question number:" << i + 1<< endl; //Display what question number.
cout << question[i] << endl; //Display question.
getline(cin, userAnswer);//Gets the input from the user, I usedgetline so the answer can have spaces in it.
//check to see if you got the answer right or wrong.
if(userAnswer == answer[i])
{
cout << "got it right \n";
numCorrect += 1;
}
if(userAnswer != answer[i])
{
cout << "got it wrong \n";
numWrong += 1;
}
}
return 0;
}
}
|