Question & Answer: he program displays the operations available and outputs the result until the use…..

Question 1 Simple calculator program(7 marks functional 2 style) Write a calculator.c program that has an accumulator value set to 0. The program displays the operations available and outputs the result until the user selects the end operator. See output example below (text in blue indicates values typed in by the user). Simple Calculator Program: type a number and an operat or, then press enter OPERATORS: + Add - Subtract S Set Accumulator E End Program 12+ acc =12. 00 3.3+ acc =15.30 -10 S acc =-10.00 24+ acc =14.00 1 E Final Value: 14.00 Goodbye! You should use a switch statement to carry the operation requested. Note that a division by zero is ignored and does not change the value of the accumulator

Write a calculator.c program that has an accumulator value set to 0. The program displays the operations available and outputs the result until the user selects the end operator. See output example below (text in blue indicates values typed in by the user). Simple Calculator Program: type a number and an operator, then press enter OPERATORS: + Add – Subtract S Set Accumulator E End Program 12 + acc =12.00 3.3 + acc =15.30 -10 s acc = -10.00 24 + acc =14.00 1 E Final Value: 14.00 Goodbye! You should use a switch statement to carry the operation requested.

Expert Answer

 

#include<stdio.h>

int main()

{

char oper=’s’;

float num,acc=0;

printf(“Simple Calculator Program:type a number and an operator,then press enter”);

printf(“nnOPERATORS:n+ Add – SubtractnnS Set Accumulator E End Programnn”);

while(oper!=’E’&&oper!=’e’)

{

scanf(“%f %c”,&num,&oper);

switch(oper)

{

case ‘+’:

acc+=num;

printf(“acc =%.2fn”,acc);

break;

case ‘-‘:

acc-=num;

printf(“acc =%.2fn”,acc);

break;

case ‘S’:

acc=num;

printf(“acc =%.2fn”,acc);

break;

case ‘E’:

{

printf(“nFinal Value: %.2fnGoodbye!”,acc);

break;

}

case ‘s’:

acc=num;

printf(“acc =%.2fn”,acc);

break;

case ‘e’:

{

printf(“Final Value: %.2fnGoodbye!”,acc);

break;

}

}

}

return 0;

}

Still stressed from student homework?
Get quality assistance from academic writers!