help with constants!

i've tried practically anything and everything, adding and removing semi-colons, setting the value to int, setting it to float, removing it in and it of the damn int main(int nNumberofArgs, char* pszArgs[]), but nothing works! please, help! this is my code;

// this program will add the number 2 to any other number, pretty
// fucking simple, right? no, not fucking simple.
//
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
int a;
int b;
int c;

a = 2;
c = 2+b;

cout << "Hey! this program adds 2 to anything! SIMPLE!" << endl;
cout << "Please enter any random number:" << endl;
cout << "your number plus 2";
cin << b;
cout << c << endl;
system ("PAUSE");
return 0;
}
It should be cin >> b;
Input is done using >>, so cin >> b;
Also, C++ is an imperative language, so order matters and you have to perform the addition after the values are known.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
int a;
int b;
int c;

a = 2;
c = 2+b;

cout << "Hey! this program adds 2 to anything! SIMPLE!" << endl;
cout << "Please enter any random number:" << endl;
cout << "your number plus 2";
cin << b;
cout << c << endl;
system ("PAUSE");
return 0;
} 


Do the addition after getting user input!
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
int main()
{
	int a;
	int b;
	int c;

	a = 2;
	

	cout << "Hey! this program adds 2 to anything! SIMPLE!" << endl;
	cout << "Please enter any random number:" << endl;
	cout << "your number plus 2";
	cin >> b; //cin is this way >>

	//add them after getting user input
	//also, using 'a' because it equals 2, like your code
	//but you never use it!
	c = a + b;

	cout << c << endl;

	//press any key to exit...
	std::cout << "\n\nPress any key to exit...";

	while( ! _kbhit() )
	{ /* do nothing - wait for key press */ }
	
	return 0;
}
Last edited on
Topic archived. No new replies allowed.