Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

My first C++ Program - Comments Requested

$
0
0
Hey there,

I decided to start teaching myself C++ this weekend.
For my first project, I wanted to make a multiple choice quiz to help my girlfriend with a state-regulated exam she has coming up (to get her Hair Cutting License).

The quiz is 25 questions long - to make it easier on your eyes, I've only included three of the questions.
The first question is commented throughout, to show you my intentions for each line of code.

As I am a total n00b to C++, I would greatly appreciate anyone who would take a minute and look over my code and give me some feedback!



#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{

//#######################################################################################
// Introduction to the program - Instructions on how to take the quiz.	

	cout<<"This is a multiple choice quiz in Hair Cut Theory"<<endl<<endl<<endl;
	cout<<"INSTRUCTIONS:"<<endl<<endl;
	cout<<"I will ask you a series of questions, to which you may reply by"<<endl;
	cout<<"pressing 'a', 'b', 'c', or 'd' followed by the 'enter' key."<<endl<<endl<<endl;
	system("pause");
	system("cls");

//#######################################################################################
// Introduces the variable that keeps track of the score.

	int addscore = 0;

//#######################################################################################
// Question 1.

	char answer1 = 'b';     //Introduces the correct answer to the problem.
	char input1;            //The user input variable for the question.
	cout<<"Question 1."<<endl<<endl;
	cout<<"Achieving balance within a design can be accomplished"<<endl;   //The Question.
	cout<<"by understanding the head shape and:"<<endl<<endl;
	cout<<"a. Head Points"<<endl;
	cout<<"b. Reference Points"<<endl;                   //The possible answers.
	cout<<"c. Four Corners"<<endl;
	cout<<"d. Technique Points"<<endl<<endl;
	cin.get(input1);        //Prompt the user for the answer to the question
	cout<<endl;
		if (input1 == answer1)     //If the user input matches the correct answer, then...
		{
			cout<<"You are correct!"<<endl<<endl;    //Display praise to the user...
			addscore++;       //and add +1 to the score count.
		}
		else {           //If the user input is incorrect, then display the correct answer and move on.
			cout<<"I'm sorry, but the correct answer was "<<answer1<<"."<<endl<<endl;
		}
		cin.get();
		system("pause");
		system("cls");

//#######################################################################################
// Question 2.

	char answer2 = 'a';
	char input2;
	cout<<"Question 2."<<endl<<endl;
	cout<<"The location of the four corners signals a change in the:"<<endl<<endl;
	cout<<"a. Head Shape"<<endl;
	cout<<"b. Bone Shape"<<endl;
	cout<<"c. Hair Texture"<<endl;
	cout<<"d. Hair Growth"<<endl<<endl;
	cin.get(input2);
	cout<<endl;
		if (input2 == answer2)
		{
			cout<<"You are correct!"<<endl<<endl;
			addscore++;
		}
		else {
			cout<<"I'm sorry, but the correct answer was "<<answer2<<"."<<endl<<endl;
		}
		cin.get();
		system("pause");
		system("cls");

//#######################################################################################
// Question 3.

	char answer3 = 'c';
	char input3;
	cout<<"Question 3."<<endl<<endl;
	cout<<"The two front corners represent the widest part of the:"<<endl<<endl;
	cout<<"a. Apex Area"<<endl;
	cout<<"b. Parietal Area"<<endl;
	cout<<"c. Bang Area"<<endl;
	cout<<"d. Nape Area"<<endl<<endl;
	cin.get(input3);
	cout<<endl;
		if (input3 == answer3)
		{
			cout<<"You are correct!"<<endl<<endl;
			addscore++;
		}
		else {
			cout<<"I'm sorry, but the correct answer was "<<answer3<<"."<<endl<<endl;
		}
		cin.get();
		system("pause");
		system("cls");

//#######################################################################################

// This is where the other 22 questions go - removed from the code to save space - you get the idea...

//#######################################################################################
// Test Results - The score is added up and presented to the user.

		cout<<"TEST RESULTS"<<endl<<endl<<endl;
		cout<<"You answered "<<addscore<<" of 25 questions correctly!"<<endl<<endl;

		system("pause");
}



Thank you for taking the time to view my post, and my beginner code.
Hopefully it didn't make your eyes bleed ;)

Any comments that you would like to share would be greatly appreciated!

ps - it looks like some of my code got structured a bit weird... I'm new to the forums, so any advice on uploading source code would be great as well. Thank you!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>