I've just learned about if statements and tried to make some sort of calculator, but it won't work. It asks you to enter an operation (for now only addition works), and then it asks for two integers. It's super simple, but it won't work. The error may be obvious to you guys, but I just don't see it. Please help! Here's the code:
int main()
{
int operation;
int addition;
float firstNumber;
float secondNumber;
printf("Type in an operation.\n");
scanf(" %s", operation);
if(operation = addition){
printf("Please, enter an integer.\n");
scanf(" %f", &firstNumber);
printf("Please, enter a second integer.\n");
scanf(" %f", &secondNumber);
printf("Answer: %d", firstNumber + secondNumber);
}else{
printf("Sorry, only addition works..");
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire