calculation error

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>

using namespace std;

int main()
{

	int a, b, c;
	cout << "enter"<<endl;
	cin >> a >> b >> c;
	cout << "ok";
	int p = (a + b) - c;
	int k = (c + b) - a;
	int m = (a * 100) + (b * 10) + (c * 1);
	int n = (c * 100) + (b * 10) + (a * 1);
	if (p>k)
	{
		cout <<m<<n;
	}

	system("pause");
	return 0;
}


Why it is not working.
enter



3
1
2
sh: pause: command not found


...because it relies on some other external program named pause that isn't installed. :-)

1. Don't use system calls if at all possible
2. When asking for input, don't say "enter" unless you just want the user to hit enter a few times. Trying numbers was a random guess
3. Ask for the input that you do want. I'm not sure what I was inputting or why. I just knew if I typed numbers I could get to the next part by glancing at the source.

enter
4 3 2 1
sh: pause: command not found
ok432234

4. it is working. it's just ugly.
system("pause") is only used in visual studio.. Can you tell why it is not displaying anything if the user entered three numbers
It does display something, or not display something, depending on the math involved.


$ ./calcnotworking.exe
enter
3
2
1
sh: pause: command not found
ok321123
$ ./calcnotworking.exe
enter
1
2
3
sh: pause: command not found
ok


Notice that its being displayed *after* the filesystem error though. Likely because there is no line feed so it's still in the buffer...

Since it's being displayed after the pause on your system too, you never get to see it because your window closes.

It's important that you believe its there though. I hope I've convinced you.
Last edited on
Topic archived. No new replies allowed.