Calculator problem

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
#include<stdio.h>
void addition();
void multiplication();
void division();
int main()
{
int opr;
printf("Renzo's calculator\n\n");

printf("Choose any desired operator\n");
printf("A: Addition\n\n");
printf("B: Multiplication\n\n");
printf("C: Division\n\n");
scanf("%d", &opr);

if (opr == 'A')
addition();

if (opr == 'B')
multiplication();

if (opr == 'C')
division();





return 0;
}

void addition()
{
int add1, add2, result;

printf("Input two number to be added\n");
scanf("%d", &add1);
scanf("%d", &add2);

result = add1+add2;

printf("%d", result);


}

void multiplication()
{
int mul1,mul2,result;

printf("Input numbers to be multiplied\n");
scanf("%d", &mul1);
scanf("%d",&mul2);

result = mul1*mul2;

printf("%d", result);



}

void division()
{
int div1,div2,result;

printf("Input numbers to be divided\n");
scanf("%d", &div1);
scanf("%d", &div2);

result = div1/div2;

printf("%d", result);


}


This is a running program btw but not running the way I wanted it to be. There's something wrong with my function call I guess.

There are no errors syntactically but probably in my logic. Can anyone spot the problem? Thanks.

This is the fourth time in 2 days I've had to post this.
http://www.cplusplus.com/forum/articles/1295/
oh c'mon not even a hint?
Do you expect someone to try to work out what the program ought to be doing, then determine why it isn't doing it?

If you have a question ask it. Have you read the link I posted?
That we can help you, we just want you to say:
1. This is my code
2. This is what it does
3. This is what I want it to do.

Point 1 you did. Ok, without using indents for a better view but you used the source-code tags, which is very helpfull for us to read.
But you missed Point 2 and 3. Also if there are no errors you could post. There should be some output or something like that which comes and which you don't want.
Last edited on
Yes. Sorry bout that.

So, my problem is after I input my choice nothing happens. The only thing that appears is the letter I chose.
Last edited on
Ok, now we know where to look for an error.

I don't know if it works with this change, but try to read a character instead of an integer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
char opr;
printf("Renzo's calculator\n\n");

printf("Choose any desired operator\n");
printf("A: Addition\n\n");
printf("B: Multiplication\n\n");
printf("C: Division\n\n");
scanf("%c", &opr);

if (opr == 'A') addition();

if (opr == 'B') multiplication();

if (opr == 'C') division();
I didn't expect that.

Thanks MaikCAE. Sorry for the ignorance too
No problem.
And it was just a hint for you how to write questions inside here if you want people to answer ;)
Last edited on
Topic archived. No new replies allowed.