I'm having a few problems, running my first program.

Dear CPlusPlus.com,

I have followed the C++ Language Tutorial (http://www.cplusplus.com/files/tutorial.pdf) but, while writing my first program (a test/poll/survey)
i ended up with a few problems.

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <iostream>
using namespace std;

int main(){

	/* Statements */
	char welcomeMsg = "Welcome to the test!";

	int score = 0;
	int totQuestions = 5;
	int totScore;

	char yes = "yes";
	char no = "no";
	char inputError = "Please try again, and give a proper answer (yes or no).";

	char startQuestion = "Would you like to start (yes or no)?";
	char startInput;

	char ansCorrect = ", is Correct! Well done!";
	char ansIncorrect = ", your answer is incorrect, please try again./t";

	char question1 = "Question 1: 1+2+3 = ...";
	char input1;
	int ans1 = 6;

	char question2 = "Question 2: 9+1 = ...";
	char input2;
	int ans2 = 10;

	char question3 = "Question 3: 2+3 = ...";
	char input3;
	int ans3 = 5;

	char question4 = "Question 4: 6+7 = ...";
	char input4;
	int ans4 = 13;

	char question5 = "Question 5: 9+... = 17";
	char input5;
	int ans5 = 8;

	char revealScore = "Your score is:";
	char congratulations = "Congratulations you have finished the test!";
	char tryagainMsg = "Would you like to try again (yes or no)?";
	char tryagainInput;

	totScore = score % totQuestions;


	/* The start */
	cout << welcomeMsg << endl;
	loopstart:
	cout << startQuestion << endl;
	cin >> startInput;
	if(startInput == yes){
		continue;
	}
	else if (startInput == no){
		return 0;
	}
	else
	{
		cout << inputError << endl;
		goto loopstart;
	}

	/* Here starts the first question */
	loopfirstquestion:
	cout << question1 << endl;
	cin >> input1;
	if(input1 == ans1)
	{
		cout << input1 << ansCorrect << endl;
		score++;
		continue;
	}
	else
	{
		cout << input1 << ansIncorrect << endl;
		score--;
		continue;
	}

	/* Here starts the second question. */
	cout << question2 << endl;
	cin >> input2;
	if (input2 == ans2){
		cout << input2 << ansCorrect << endl;
		score++;
		continue;
	}
	else
	{
		cout << input2 << ansIncorrect << endl;
		score--;
		continue;
	}

	/* Here starts the third question. */
	cout << question3 << endl;
	cin >> input3;
	if (input3 == ans3){
		cout << input3 << ansCorrect << endl;
		score++;
		continue;
	}
	else
	{
		cout << input3 << ansIncorrect << endl;
		score--;
		continue;
	}

	/* Here starts the fouth question */
	cout << question4 >> endl;
	cin >> input4;
	if (input4 == ans4){
		cout << input4 << ansCorrect << endl;
		score++;
		continue;
	}
	else
	{
		cout << input4 << ansIncorrect << endl;
		score--;
		continue;
	}

	/* Here starts the fifth question. */
	cout << question5 << endl;
	cin >> input5;
	if (input5 == ans5){
		cout << input5 << ansCorrect << endl;
		score++;
		continue;
	}
	else
	{
		cout << input5 << ansIncorrect << endl;
		score--;
		continue;
	}

	cout << revealScore << totScore << endl;
	if (totScore == 100){
		cout << congratulations << endl;
		return 0;
	}
	else
	{
		looptryagain:
		cout << tryagainMsg << endl;
		cin >> tryagainInput;
		if(tryagainInput == yes){
		goto loop1;
		}
		else if (tryagainInput == no){
			return 0;
		}
		else
		{
			cout << inputError << endl;
			goto looptryagain;
		}
	}
}


Please, take a few minutes to help me.
I will only learn from my mistakes if i'm able to see the problem.
And could you give a few tips/tricks?

Thanks in advance,
Clipsed
i ended up with a few problems.

?

Can you be more specific please?

that link doesnt work, but this looks a very bad tutorial if it's telling you use things like "goto", or is your code?. Also:
char welcomeMsg = "Welcome to the test!";
i'm not sure why a C++ tutorial would suggest using nasty c-style string (plus that would need to be a char pointer, so it's very wrong).


You'd be better off using the up to date tutorials on this site as a starter.
http://www.cplusplus.com/doc/tutorial/
Last edited on
Topic archived. No new replies allowed.