Please Help to this Calculator Program in Dev C++

I Want to do a Calculator Program! My problem is i want to output my program like this! so that the output will display clear screen after type the variable and operation! (Variable) (Operation) (Variable) = (Answer)

also i want to know what kind of codes also i need to output a program like

(Variable) (Addition) (Variable) (Subtraction ) (Variable) (Division) (Variable) (Multiplication) (Variable) = Answer

Sample Output

Enter a Number that you want to computer : 5
Enter a operation that you want to use : +
Enter a Number that you want to computer : 5
Enter a operation that you want to use : -
Enter a Number that you want to computer : 4
Enter a operation that you want to use : /
Enter a Number that you want to computer : 3
Enter a operation that you want to use : *
Enter a Number that you want to computer : 2
Answer is : 4



(Variable) (Operation) (Variable) = (Answer)

Enter Your 1st Number : 1
The Operation is : Addition ( + )
Enter Your 2nd Number : 1
Answer : The Sum of 1 and 1 is 2


but im my code i can do a program w/ this output

(Operation) (1st Variable) (2nd Variable) = (Answer)

What is the code that i need to do a program with the output on the upper part?

this is my code

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
main()
{

menu();
getch();
}

menu()
{
int iSel;

printf("\t\t<<Menu>>\n\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("5. Clear Screen\n");
printf("0. Exit\n\n");
printf("Select Operation: ");
scanf("%d", &iSel);

if(iSel == 1)
Addition();
else if(iSel == 2)
Subtraction();
else if(iSel == 3)
Multiplication();
else if(iSel == 4)
Division();
else if(iSel == 5)
{

menu();
}
else if(iSel == 0)
printf("Thank You and Goodbye!\n");
else
printf("ERROR\n");
}

Addition()
{
int iNum1, iNum2, iSum;

printf("Enter First Number: ");
scanf("%d", &iNum1);
printf("Enter Second Number: ");
scanf("%d", &iNum2);

iSum = iNum1 + iNum2;

printf("The Sum of %d and %d is %d\n\n", iNum1, iNum2, iSum);

menu();
}

Subtraction()
{
int iNum1, iNum2, iDiff;

printf("Enter First Number: ");
scanf("%d", &iNum1);
printf("Enter Second Number: ");
scanf("%d", &iNum2);

iDiff = iNum1 - iNum2;

printf("The Difference of %d and %d is %d\n\n", iNum1, iNum2, iDiff);

menu();
}

Multiplication()
{
int iNum1, iNum2, iPro;

printf("Enter First Number: ");
scanf("%d", &iNum1);
printf("Enter Second Number: ");
scanf("%d", &iNum2);

iPro = iNum1 * iNum2;

printf("The Product of %d and %d is %d\n\n", iNum1, iNum2, iPro);

menu();
}

Division()
{
int iNum1, iNum2, iQuo;

printf("Enter First Number: ");
scanf("%d", &iNum1);
printf("Enter Second Number: ");
scanf("%d", &iNum2);

iQuo = iNum1 / iNum2;

printf("The Quotient of %d and %d is %d\n\n", iNum1, iNum2, iQuo);

menu();
}


This is the Print Screen of my Output in my code

http://i972.photobucket.com/albums/ae202/trisha000/1-5.png
Last edited on
Up :D
What do you want us to do with this? It can be improved.
are you trying to make simple thing complicated?
Im Just trying to Expand dis code in this kind of output

Variable 
Operation
Variables
Operation
.
.
.
.
Answer


plz create a program that simple.. :D
Clearing the screen:
cout << string(50, '\n'); //better

system("CLS"); //ok but not for production code

Just an idea - u could print instructions at the top and have the user press the intuitive buttons like +-/* and = when they are done. Ideally they should be able to make about as many operations as they feel like. U can handle this by using arrays to store each variable and operation order. U'll need a way to parse the input to make it efficient...

Instead of telling them what each of operations are with words u could use symbols. Everyone knows that 2+2=4 means "The Sum of 2 and 2 is 4"
Last edited on
You mean like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main(void) {
	char op;
	float ans = 0, num1;
	while(op != '=') {
		std::cout << "Calculation: ";
		std::cin >> num1 >> op;
		switch(op) {
			case('+'): ans+=num1; break;
			case('-'): ans-=num1; break;
			case('/'): ans/=num1; break;
			case('*'): ans*=num1; break;
		}
	}
	std::cout << "Answer: " << ans << std::endl;
	return 0;
}

Sample Input:
1
2
3
4
5
Calculation: 5+
Calculation: 3+
Calculation: 3*
Calculation: 4= // does nothing
Ans: 24

Or like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main(void) {
    char op;
    float num1, num2;
    std::cout << "Calculation: ";
    std::cin >> num1 >> op >> num2;
    switch(op) {
    	case('+'):
    		std::cout << num1 << ' ' << op << ' ' << " = " << num1+num2;
    		break;
    	case('-'):
    		std::cout << num1 << ' ' << op << ' ' << " = " << num1-num2;
    		break;
    	case('/'):
    		std::cout << num1 << ' ' << op << ' ' << " = " << num1/num2;
    		break;
     	case('*'):
    		std::cout << num1 << ' ' << op << ' ' << " = " << num1*num2;
    		break;
    }
	return 0;
}

Sample Input:
1
2
Calculation: 5*5
5 * 5 = 25

You really should just re-code your program. But this time try keep it simple.
Last edited on
@xhtmlx

I Think Like this

Calculation: 5+
Calculation: 3+
Calculation: 3*
Calculation: 4=
Ans: 24



i already re-code my program this is possible to put a code by 2 switch?

my prof told me try to code your program in

(VARIABLE) (OPERATION) (VARIABLE) = (ANSWER) (OPERATION) (VARIABLE) = (ANSWER) . . . . . . . . . . . . . . ETC. = ANSWER

SO MAYBE WILL BE TERMINATED IN 1 KEY SO THAT THE FINAL ANSWER SHOW UP :D

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdio.h>
#include<stdlib.h>
main()
{
	int iNum1;
    int iNum2;
    int iSum;
    int iDiff;
    int iPro;
    float iQuo;
    int iMod;
	int cOp;

    printf("\n\t\t\t\t<<Menu>> \n\n");
	printf("Choose the Operation that you want to use! Just type the Number\n\n");
	printf("[1] Addition (+) Operation\n");
	printf("[2] Subtraction (-) Operation\n");
	printf("[3] Multiplication (*) Operation\n");
	printf("[4] Division (/) Operation\n");
	printf("[0] To Get the Answer / Terminate\n\n");
	printf("Enter your Operation : ");
	scanf("%d", &cOp);

	switch(cOp){
		case 1:
            printf("\nYour Operation is Addition\n");
			printf("Enter Addend Number: ");
			scanf("%d", &iNum1);
			printf("Enter another Addend Number: ");
			scanf("%d", &iNum2);
			iSum = iNum1;

			while(iNum2 != 0)
			{
			iSum = iSum + iNum2;
			printf("Enter Another Addend Number: ");
			scanf("%d", &iNum2);
			}
			printf("The Sum is %d\n", iSum);
			break;

		case 2:
            printf("\nYour Operation is Subtraction\n");
			printf("Enter Minuend Number: ");
			scanf("%d", &iNum1);
			printf("Enter Subtrahend Number: ");
			scanf("%d", &iNum2);
			iDiff = iNum1;
			
			while(iNum2 != 0)
			{
			iDiff = iDiff - iNum2;
			printf("Enter another Subtrahend Number: ");
			scanf("%d", &iNum2);
			}
			printf("The Difference is %d\n", iDiff);
			break;

		case 3:
            printf("\nYour Operation is Multiplication\n");             
			printf("Enter Factor Number: ");
			scanf("%d", &iNum1);
			printf("Enter another Factor Number: ");
			scanf("%d", &iNum2);
			iPro = iNum1;
			
			while(iNum2 != 0)
			{
			iPro = iPro * iNum2;
			printf("Enter another Factor Number: ");
			scanf("%d", &iNum2);
			}
			printf("The Product is %d\n", iPro);
			break;

		case 4:
            printf("\nYour Operation is Division\n");             
			printf("Enter Dividend Number: ");
			scanf("%d", &iNum1);
			printf("Enter Divisor Number: ");
			scanf("%d", &iNum2);
			iQuo = iNum1;
			
			while(iNum2 != 0)
			{
			iQuo = iQuo / iNum2;
			printf("Enter another Divisor Number: ");
			scanf("%d", &iNum2);
			}
			printf("The Quotient is %.2f\n", iQuo);
			break;

		default:
			printf("\nOpss. . . Error!!!\n\n");
			break;
	}

system("PAUSE");
getchar();

}


pls basic code only like

printf and scanf string :D tnx
Last edited on
up
not sure what u'r looking for. do u want to use the answer from the previous operation as the first input for the next one ? what input is for the user then ?
(VARIABLE) (OPERATION) (VARIABLE) = (ANSWER) (OPERATION) (VARIABLE) = (ANSWER) . . . . . . . . . . . . . . ETC. = ANSWER
not sure what u'r looking for. do u want to use the answer from the previous operation as the first input for the next one ? what input is for the user then ?

(VARIABLE) (OPERATION) (VARIABLE) = (ANSWER) (OPERATION) (VARIABLE) = (ANSWER) . . . . . . . . . . . . . . ETC. = ANSWER


maybe like u are saying previous operation also maybe can use for the new operation

what if the user input the ADDITION OPERATION from his previous task after getting the answer. . . the user will be input new operation Ex. MULTIPLICATION, SUBTRACTION OR DIVISION depend for the user!

in short i making a perfect calculator instead continuous calculator :D
up
The only thing I see in these posts is horrible grammar.
Topic archived. No new replies allowed.