Hello I wrote a few hours earlier and Ive been working on it. I am trying to write a calculator program the output should be:
1. addition
2. subtraction
3. multiplicaiton
4. division
5. Exit
please select an operand?
please enter two numbers separated by a space: ?
the result of %f and % f is %f.
I've tried for a while. I am not sure about the while loop. Any help woould be very much appreciated! I can't attach the code below so i copied pasted it:
Code:
#include<stdio.h>
float choice;
float result;
float num1, num2;
int get_choice();
int main()
{
{
float num1, num2;
int choice;
float result;
do
{
printf("Welcome to Colleen Gonzales's Handy Calculator");
printf("1. Addition\n");
printf("2. Subtract\n");
printf("3. Multipilcation\n");
printf("4. Division\n");
printf("5. Exit\n");
printf("\n\nPlease pick an operation.\n");
scanf("%f", &choice);
}
while( (choice = 1,2,3, 4 , 5) );
printf("Please choose two numbers seperated by a space:");
scanf("%f %f", &num1, &num2);
return 0;
}
{
float num1, num2, result;
int choice;
while( (choice=get_choice()) !=5)
{
switch (choice)
{
case 1 : result = num1 + num2;
break;
case 2 : result = num1-num2;
break;
case 3 : result = num1 * num2;
break;
case 4 : result = num1/num2;
break;
case 5 : printf("Goodbye");
break;
default :printf("Please respond with 1, 2, 3, 4, or 5\n");
break; /*end of switch*/
}
}
printf("The result of %f and %f is %.2f\n", &num1, & num2, &result);
return 0;
}
}