frustrating errors

hi guys, im trying to get a program that requires a input of numbers and add them up, requiring the user to supply number each time using a do loop, ive done what i think is correct but i keep getting these errors:

(6) : error C2059: syntax error : 'do'
(8) : error C2143: syntax error : missing ';' before '{'
(8) : error C2447: '{' : missing function header (old-style formal list?)
here is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main ();
int total, number;
char answer;
do;
		{
		cout  << "input a number" <<endl;
		cin >> number;
		total = total + number
		cout << "any more?"<<endl;
		cin >> answer;
while 	(reply != ‘n’)
cout << total;
		}

Replace the semicolon on line 3 with an opening bracket.
Replace the semicolon on line 6 with an opening bracket and add a semicolon on line 13.
Last edited on
like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main ()(
int total, number;
char answer;
do(
		{
		cout  << "input a number" <<endl;
		cin >> number;
		total = total + number;
		cout << "any more?"<<endl;
		cin >> answer;
		while 	(reply != ‘n’);
		cout << total;
		}

		
I said you should add an opening bracket on line 6. That wasn't really true. What I meant to say was that you should add an closing bracket on line 13 before while.

By bracket I mean curly brackets { }.
Im very confused, so this is what ur asking me to do?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
int main (){
int total, number;
char answer;
do
		{
		cout  << "input a number" <<endl;
		cin >> number;
		total = total + number
		cout << "any more?"<<endl;
		cin >> answer;
		}
while 	(reply != ‘n’);
cout << total;
} 

Last edited on
Almost, but you have a few brackets too many. Use proper indentation in your code and it will be obvious where.

You also have to create a variable named reply and ‘n’ should be 'n'.
Ok thankyou for your help, i just face this final error :

(16) : error C2065: 'reply' : undeclared identifier

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main ()
{
int total, number;
char answer;

do
{
	cout  << "input a number" <<endl;
	cin >> number;
	total = total + number;
	cout << "any more?"<<endl;
	cin >> answer;
}
while 	(reply != 'n');
cout << total;
return 0;
}

Last edited on
You have no variable called reply
hmm.. ok thank you.
Hi, peter if you're still there i still require help. I have declared (well i think i have) reply as a variable but i keep getting these warnings:

(11) : warning C4700: uninitialized local variable 'total' used
(15) : warning C4700: uninitialized local variable 'reply' used

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <iostream>
using namespace std;
int main ()
{
int total, number;
char answer, reply;
do
{
	cout  << "input a number" <<endl;
	cin >> number;
	total = total + number;
	cout << "any more?"<<endl;
	cin >> answer;
}
while 	(reply != 'n');
cout << total;
return 0;
}


im really sorry to bug you like this but im less than a beginner in c++ :(
Last edited on
The warning is because you are using reply but you have never given it a value.

You have to know what you are trying to do.
like this?

#include <iostream>
using namespace std;
int main ()
{
int total, number;
char answer, reply;
reply = 0;
total= 0;
I don't know. You probably want to do more than that, otherwise your code will never end. Maybe you want reply to be the same as answer? In that case just remove reply and replace it with answer on line 16.
Last edited on
ok this works, thank you.
Topic archived. No new replies allowed.