What Is Wrong With This C Code?

vlaki007

Estimable
Sep 28, 2015
1
0
4,510
0
#include <stdio.h>
#include <stdlib.h>


int main()
{
int x;
int y;
int answer;
int operationType;

printf("Welcome to Vladimir's calculator \n");

printf("What do you want me to do? \n 1.add ; 2.subtrack ; 3.devide ; 4.multiply \n");
scanf(" %d \n", &operationType);

if(operationType == 1){
printf("You have chosen to add! \n Give me 1st number: ");
scanf(" %d \n", &x);
printf("give me the 2nd number: ");
scanf(" %d \n", &y);

answer = x + y;

printf(" %d \n", answer);
}
if(operationType == 2){
printf("You have chosen to subtrackt! \n Give me 1st number: ");
scanf(" %d \n", &x);
printf("give me the 2nd number: ");
scanf(" %d", &y);

answer = x - y;

printf(" %d + %d = %d", x, y, answer);
}
if(operationType == 3){
printf("You have chosen to devide! \n Give me 1st number: ");
scanf(" %d \n", &x);
printf("give me the 2nd number: ");
scanf(" %d", &y);

answer = x / y;

printf(" %d", answer);
}
if(operationType == 4){
printf("You have chosen to multiply! \n Give me 1st number: ");
scanf(" %d \n", &x);
printf("give me the 2nd number: ");
scanf(" %d", &y);

answer = x + y;

printf(" %d", answer);
}
printf("The end");

return 0;
}

// no errors accure, but it does not give the right answer
 
Thread starter Similar threads Forum Replies Date
A Apps General Discussion 1
O Apps General Discussion 6
A Apps General Discussion 2
Z Apps General Discussion 8
D Apps General Discussion 5
L Apps General Discussion 1
B Apps General Discussion 3
A Apps General Discussion 2
A Apps General Discussion 13
B Apps General Discussion 2
A Apps General Discussion 5
D Apps General Discussion 1
S Apps General Discussion 2
S Apps General Discussion 4
L Apps General Discussion 8
A Apps General Discussion 1
G Apps General Discussion 3
H Apps General Discussion 10
Wing0 Apps General Discussion 8
S Apps General Discussion 1

ASK THE COMMUNITY