Problems with Calculator Program

Pages: 12
Thanks or the info guys but to quote Kaduuk

} //notice that the return 0 should be outside the loop, because otherwise it'd have to terminate the program every time it loops, which isn't possible :p
return 0;
} //end of main


You can terminate it but it would have to be ended through Task Manager processes. Not tryin to be smart just saying that u can :]
As for the above comment, he was saying that it would not be possible to continue looping, because of termination, it was just said backwards to be amusing. as it was, it was terminating at the bottom of the loop, so task manager is pointless when poor coding style has already achieved the termination.

Comments are useful for: A: yourself and B: other programmers, to understand what your code is trying to achieve.

Sorry to say but your comments are completely pointless, comments should be reserved for particular blocks of code that could be ambiguous or at the start of a block of code to explain what is happening.

// Welcome the User...
cout << "******Welcome to My DOS Calculator******" << endl;
cout << "________________________________________" << endl;
cout << endl;

is pointless as we can already see by the output that you are welcoming the user.

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
// include comments here to give your name, date, company, school
// piece of assesment, eg. Oct 2010 Assignment 8.
// this is mostly useful for yourself :-)

#include <iostream>
using namespace std;

int main()
{
	double first_number;
	double second_number;
	char operation;
	double go_on = 5; // not used. remove before release

        char ans;  // user answer y/n for sentinel loop

	while(ans!='n') 
	{
		cout << "******Welcome to My Calculator******" << endl;
		cout << "____________________________________" << endl;
		cout << endl;

		cout << "Please input the First Number..." << endl;
		cin >> first_number;

		cout << "Please input a Operation (i.e. + - / *)" << endl;
		cin >> operation;

		cout << "Please input the Second Number..." << endl;
		cin >> second_number;

		if( cin, operation == '+' )
			cout << first_number << " + " << second_number << " = "  
				<< first_number+second_number << endl;

		if( cin, operation == '-' )
			cout << first_number << " - " << second_number << " = " 
				<< first_number-second_number << endl;

		if( cin, operation == '/' )
			cout << first_number << " / " << second_number << " = " 
				<< first_number/second_number << endl;

		if( cin, operation == '*' )
			cout << first_number << " * " << second_number << " = " 
				<< first_number*second_number << endl;

		cout<<"would you like to continue (y/n)?"; 
		cin>>ans;
	} 

	return 0;

} //end main   


Edit: Notice I only comment one of your variables? "ans" this is probably the only ambiguous variable out of the group. The others are simply named, and have simple uses.
Last edited on
http://cplusplus.com/forum/beginner/27467/#msg147669

sorry. I didn't know that. When I asked a similar question elsewhere I got a lot of replies saying that, so I assumed that you needed to know a lot about c++ before going to windows programming...

Actually I also want to do that :P
Topic archived. No new replies allowed.
Pages: 12