26 errors 2 warnings

i messed up my post
Last edited on
Try adding some semicolons after the variable declaration. And I believe it is a syntax error to declare a variable beginning with a number. That should get you going.
Thankyou verry much it fixed the problem! i changed the variable declaration to a and b and added semicolons.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
using namespace std;

int main() 
{
	int a;
	int b;
	cout << "Adding Numbers" << endl;
	cout << "First Number: ";
	cin >> a;
	cout << "Second Number: ";
	cin >> b;
	cout << "Your number is: " << a + b << endl;
	return 0;
}
hi i am working on the same thing but updated it and need help again.

#include <iostream>
#include <string>
using namespace std;

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
int main() 
{
	int A;
	int B;
	int a;
	int b;
	int c;
	int d;
	cout << "Choose A or B" << endl;
	cout << A <<".Adding Numbers" << endl;
	cout << B <<".Subtracting Numbers" << endl;
	if 'A';
	cout << "Adding Numbers" << endl;
	cout << "First Number: ";
	cin >> a;
	cout << "Second Number: ";
	cin >> b;
	cout << "Your number is: " << a + b << endl;
	if 'B';
	cout << "Subtracting Numbers" << endl;
    cout << "First Number: ";
	cin >> c;
	cout << "Second Number: ";
	cin >> d;
	cout << "Your number is: " << c - d << endl;
	return 0;
}


what is a constant?
my c++ calculator im almost done with

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
int userInput = 0;
int endInput = 0;
int a;
int b;
int c;
int d;
int e;
int f;
double g;
double h;

cout << "Simple Calculator By Gaggerzon" << endl;
cout << "CHOOSE 1 - 4" << endl;
cout << "1.Adding Numbers" << endl;
cout << "2.Subtracting Numbers" << endl;
cout << "3.Multiplying Numbers" << endl;
cout << "4.Dividing Numbers" << endl;
cin >> userInput;
if (userInput != 1 && userInput != 2 && userInput != 3 && userInput != 4 )
{
cout << "Please Apply the Correct Number" << endl;
}
if (userInput == 1)
{
cout << "Adding Numbers" << endl;
cout << "First Number: ";
cin >> a;
cout << "Second Number: ";
cin >> b;
cout << "Your number is: " << a + b << endl;
}
if (userInput == 2)
{
cout << "Subtracting Numbers" << endl;
cout << "First Number: ";
cin >> c;
cout << "Second Number: ";
cin >> d;
cout << "Your number is: " << c - d << endl;
}
if (userInput == 3)
{
cout << "Multiplying Numbers" << endl;
cout << "First Number: ";
cin >> e;
cout << "Second Number: ";
cin >> f;
cout << "Your number is: " << e * f << endl;
}
if (userInput == 4)
{
cout << "Dividing Numbers" << endl;
cout << "First Number: ";
cin >> g;
cout << "Second Number: ";
cin >> h;
cout << "Your number is: " << g / h << endl;
}
}
Personally, I would use variables that are a little less confusing and have some meaning; i.e. num2 for second number. I would also put the selection in a switch structure to make the program more fault tolerable. I had a similar project that mimics a basic calculator.
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
#include <iostream>

using namespace std;

int main()
{
	int result, num1, num2, choice;
	cout<<"Enter the numbers: "<<endl;
	cin>>num1>>num2;
	cout<<"\nPress 1 to add, 2 to subtract, 3 to multiply, 4 to divide: "<<endl;
	cin>>choice;
	switch(choice)
	{
	case 1:
		result = num1 + num2;
		cout<<num1<<" + "<<num2<<" = "<<result<<endl;
		break;
	case 2:
		result = num1 - num2;
		cout<<num1<<" - "<<num2<<" = "<<result<<endl;
		break;
	case 3:
		result = num1 * num2;
		cout<<num1<<" * "<<num2<<" = "<<result<<endl;
		break;
	case 4:
		if(num2 == 0)
			cout<<"Division by zero not allowed."<<endl;
		else
		{
			result = num1 / num2;
			cout<<num1<<" / "<<num2<<" = "<<result<<endl;
		}
		break;
	default:
		cout<<"Invalid input."<<endl;
	}
	return 0;
}
omg how long did it take you to make that
i suck so bad at c++
it took me 3 hours just to make a gay calculator
u must be smart in c++
I've been studying software engineering for a year, part of my Game Software Development major, I am just now getting into the programming. Do you have any C++ reading material? I would suggest some but all of mine is created specifically for the college I attend. This is the best C++ website forum I could find and the people are helpful and firendly. Just practice, practice, practice. As an amateur, the best advice I can give is to master parameter passing and templates early on.
The best advice for any beginner is not to type a single character without knowing why it is needed. Don't just copy and paste; read and understand it.
yeah if you found an example dont copy and paste, type it manually so you will be familiar in its syntax later. then most of all take time to understand it, dont be in a hurry. i suggest reading the tutorial in this website.
Typing out all examples provided by my textbook has done wonders for me, not only for syntax reasons either. I seem to retain the information better as well as gain a deeper understanding of it versus just reading. Where I find myself really lacking is the small, what seem like minor, math computations that completely alter the output. Like the following:
1
2
3
4
5
6
7
8
	int j, i;
	j = 2;
	for(i = 0; i <= 5; i++)
	{
		cout<<j<<" ";
		j = 2 * j + 3;
	}
	cout<<j<<" "<<endl;
u guys are right...
but were i live, there is no programming language class so it sucks
Im making a ColaMachine. can somebody tell me wahts wrong with this?

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
#include <iostream>
using namespace std;

int main()
{
	int userInput = 0;
	int endInput = 0;
	
	cout << "COLA MACHINE" << endl;
	system ('PAUSE');
	cout << "Use 25 Cents? (y=5/n=6)" << endl;
	cin >> userInput;
	if (userInput != 5 && userInput != 6)
	{
		cout << "Oh No, You Dropped Your Coin!" << endl;
		return 0;
	}
	if (userInput == 6)
	{
		cout << "Okay, See You Later!" << endl;
		return 0;
	}
	if (userInput == 5)
	{
		cout << "Choose 1 - 4" << endl;
		system ('PAUSE');
		cout << "1.Cola" << endl << "2.Sprite" << endl;
		cout << "3.Water" << endl << "4.Lemonade" << endl;
		cin >> endInput;
		if (endInput != 1 && endInput != 2 && endInput != 3 && endInput != 4 )
{
cout << "Please Apply the Correct Number" << endl;
}
if (endInput == 1)
{
cout << "Thankyou for Buying The Cola!" << endl;
return 0;
}
if (endInput == 2) 
{
cout << "Thankyou for Buying The Sprite!" << endl;
return 0;
}
if (endInput == 3) 
{
cout << "Thankyou for Buying The Water!" << endl;
return 0;
}
if (endInput == 4) 
{
cout << "Thankyou for Buying The Lemonade!" << endl;
return 0;
}
	}
}
	
'system ('PAUSE')' should be 'system ("PAUSE")'; then it will compile
Last edited on
system("PAUSE") should die.

http://www.cplusplus.com/forum/articles/7312/
Topic archived. No new replies allowed.