Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3-2 Please do the coding in C language! 3.2 Here is a calculator program. The pr

ID: 3814153 • Letter: 3

Question

3-2

Please do the coding in C language!

3.2 Here is a calculator program. The program gives a prompt and waits for user to enter a number, operator and another number and gives the output like this Type a number operator number separated by a space 12 34 12.00 34.00 46.00 Another run looks like this: Type a number operator number separated by a space 12 12 12.00 12.00 144.00 #include stdio.h int main() int firstN int second char op; printf("Type a number, operator number separated by a space scanf ("%d %C %d", &firstN;, &op;, &second; N);

Explanation / Answer

#include <stdio.h>
#include <string.h>

int main()
{
double firstN, secondN;
char op;
char ch[20];
do{
  
printf(" Type a number, operator, number -- seperated by a space: ");
scanf("%lf %c %lf", &firstN,&op,&secondN);
  
if(op=='+'){
printf("%lf + %lf = %lf", firstN,secondN,(firstN + secondN) );
}
else if(op=='-'){
printf("%lf - %lf = %lf", firstN,secondN,(firstN - secondN) );
}
else if(op=='*'){
printf("%lf * %lf = %lf", firstN,secondN,(firstN * secondN) );
}
else if(op=='/'){
printf("%lf / %lf = %lf", firstN,secondN,(firstN / secondN) );
}
else
{
printf(" Unknown operator");
}
printf("Do you want to continue (Yes/No)");
scanf("%s",ch);
  
if(!(strcmp(ch, "Yes") ==0))
break;
}while(1==1);
  
printf(" ");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote