- Joined
- Jun 10, 2008
- Messages
- 117
- Reaction score
- 0
I made a quick quiz for you all to look at. Basically all it does it ask questions. You can read it over and study the code to help you understand a little bit more on basic C++ functions.
This DOES compile so do not worry about errors. Tell me anything you have questions with and i will answer to the best of my ability.
Code:
#include <iostream>
#include "string"
using namespace std;
int main(){
//variables
int correct = 0;
int incorrect = 0;
int diff;
string name;
//introduction
cout << "Welcome to the quiz!" << endl;
cout << "Please enter your name:" << endl;
cin >> name;
//Difficulty level
cout << "Hello " << name << ", please enter the difficulty level (1, 2, 3):" << endl;
cin >> diff;
//clears the screen
system("cls");
//Game start
if(diff == 1){
//Question 1
cout << "Question 1:\nHow many stripes are on the American Flag?" << endl;
int stripes;
cin >> stripes;
if(stripes == 13)
{
//If they answered correctly then the number correct goes up.
cout << "Correct! Lets move to the next question." << endl;
correct++;
system("pause");
}else{
//If they answered incorrectly then the number incorrect goes up.
cout << "Sorry! Incorrect answer." << endl;
incorrect++;
system("pause");
}
//Question 2
system("cls");
//Score Display
cout << "Correct:" << correct << "Incorrect:" << incorrect << endl;
cout << "Question 2:\nHow many letters are in the Alphabet?" << endl;
int alph;
cin >> alph;
if(alph == 26)
{
cout << "Correct! There are 26 letters in the English Alphabet" << endl;
correct++;
system("pause");
}else{
cout << "Sorry! Incorrect answer." << endl;
incorrect++;
system("pause");
}
//Question 3
system("cls");
cout << "Correct:" << correct << "Incorrect:" << incorrect << endl;
cout << "Final question!\nWhat is the name you input at the beginning of the quiz?" << endl;
string name2;
cin >> name2;
if(name2 == name){
cout << "Correct!" << endl;
correct++;
system("pause");
}else{
cout << "Sorry! Incorrect answer." << endl;
incorrect++;
system("pause");
}
system("cls");
if(correct >= 2){
cout << "Congratulations, you scored " << correct << " correct!" << endl;
system("pause");
}
else if(incorrect >= 2){
cout << "I'm Sorry!, you scored " << incorrect << " incorrect." << endl;
system("pause");
}
}else if(diff == 2){
cout << "Incopmlete!";
system("pause");
}else if(diff == 3){
cout << "Incopmlete!";
system("pause");
}
return 0;
}
This DOES compile so do not worry about errors. Tell me anything you have questions with and i will answer to the best of my ability.

