Hi guys,
I am trying to program the following type calculator:
Welcome to <John Doe’>s Handy Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
What would you like to do? 3
Please enter two numbers to multiply separate by a space: 24 6
Result of multiplying 24.00 and 6.00 is 96.00.
Press any key to continue …
..........................................
I am stuck on the "Result....." line. First off I can't get the result to appear as a float (or at all for that matter). I am sure it is something basic I am doing incorrectly. Also I can't figure out how to place the "and" between the 2 numbers in the printf() statement.
I am currently testing it under Case 1 in the code as you can see.
You don't have to do it for me, just a push in the right direction would be appreciatedThanks
Code:#include <stdio.h> int main() { int value; int num1,num2; float result; num1=0; num2=0; result=0; printf("Welcome to xxxxxxx's handy calculator\n"); printf(" 1. Addition\n"); printf(" 2. Subtraction\n"); printf(" 3. Multiplication\n"); printf(" 4. Division\n"); printf(" 5. Exit\n"); printf("What would you like to do?"); scanf("%d",&value); if(value>5 || value<1) { printf("You have entered an incorrect number"); } switch (value) { case 1: printf("Please enter two numbers to add separate by a space: "); scanf("%d %d",&num1,&num2); printf("Result of adding %d+%d is: %2.2f",num1, num2, result); break; case 2: printf("Please enter two numbers to subtract separate by a space: "); break; case 3: printf("Please enter two numbers to multiply separate by a space: "); break; case 4: printf("Please enter two numbers to divide separate by a space: "); break; } return 0; }



LinkBack URL
About LinkBacks
Thanks


