write a C program to perform simple C arithmetic calculations. The user is to en
ID: 672984 • Letter: W
Question
write a C program to perform simple C arithmetic calculations. The user is to enter a simple expression (integer operator integer) such as 15 + 30 The program is to extract the 2 operands and the operator, perform the indicated calculation and display the result. For example 15 + 30 = 45 Operators should include + , - , * , / , and % Operands are positive integers , no sign Use getchar to input the expression Allow for variable spacing before the first operands and between operators and operands ( 0, 1, or more spaces)Allow the user the option of entering another expression Code a function for each operator to do the appropriate arithmetic operations (5 functions) No global variables No string handling functions No arrays May only use input and output functions such as getchar and putchar
Input: interactive. Allow the user to enter multiple expressions
Output: Echo the input ( both user prompts and the user entered data ) Print the whole expression , with the result or an appropriate error message. Be sure output data shows all valid and invalid test data and how your program handled it. write a C program to perform simple C arithmetic calculations. The user is to enter a simple expression (integer operator integer) such as 15 + 30 The program is to extract the 2 operands and the operator, perform the indicated calculation and display the result. For example 15 + 30 = 45 Operators should include + , - , * , / , and % Operands are positive integers , no sign Use getchar to input the expression Allow for variable spacing before the first operands and between operators and operands ( 0, 1, or more spaces)
Allow the user the option of entering another expression Code a function for each operator to do the appropriate arithmetic operations (5 functions) No global variables No string handling functions No arrays May only use input and output functions such as getchar and putchar
Input: interactive. Allow the user to enter multiple expressions
Output: Echo the input ( both user prompts and the user entered data ) Print the whole expression , with the result or an appropriate error message. Be sure output data shows all valid and invalid test data and how your program handled it. write a C program to perform simple C arithmetic calculations. The user is to enter a simple expression (integer operator integer) such as 15 + 30 The program is to extract the 2 operands and the operator, perform the indicated calculation and display the result. For example 15 + 30 = 45 Operators should include + , - , * , / , and % Operands are positive integers , no sign Use getchar to input the expression Allow for variable spacing before the first operands and between operators and operands ( 0, 1, or more spaces)
Allow the user the option of entering another expression Code a function for each operator to do the appropriate arithmetic operations (5 functions) No global variables No string handling functions No arrays May only use input and output functions such as getchar and putchar
Input: interactive. Allow the user to enter multiple expressions
Output: Echo the input ( both user prompts and the user entered data ) Print the whole expression , with the result or an appropriate error message. Be sure output data shows all valid and invalid test data and how your program handled it.
Explanation / Answer
Calculator program in C language , See below code -
#include <stdio.h>
main()
{
float a, b, c, e;
char d;
while (1) // ** added
{ // ** added
printf("Enter the first number");
scanf("%f",&a);
getchar();
printf("set d(the function):");
scanf("%c",&d);
getchar();
printf("Enter the second number");
scanf("%f",&b);
getchar();
//printf("set the limit");
//scanf("%f",&c);
//getchar();
// while (1==1) ** removed
//{ ** removed
if (d=='*')
{
a=a*b;
}
if (d=='/')
{
a=a/b;
}
if (d=='+')
{
a=a+b;
}
if (d=='-')
{
a=a-b;
}
if (d=='%')
{
a=a*b/100;
}
printf("value is %f ",a);
// getchar(); ** removed
}
printf("final value is %f",a);
getchar();
//main(); ** removed
}
//} ** removed
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.