Question
C Programming - Newbie Hello I am using replit(.)com. that is why there is (void) in scanf because replit shows a warning. I just need
C Programming - Newbie
Hello I am using replit(.)com. that is why there is (void) in scanf because replit shows a warning. I just need a little help. How can I fix this? It automatically go into this "printf(" \t\t PLEASE ENTER THE TWO NUMBERS "); " instead of typing first the operatot. Also, if you have a better idea please develop this one in C programming.
//Final Project: Basic Calculator //A Program for Basic Calculator #include
printf("Hi! This program can calculate two numbers. Do you want to proceed? (Y/N)"); (void) scanf(" %c", &ch);
if(ch == 'y' || ch == 'Y'){ goto print; } else if(ch == 'n' || ch == 'N'){ return 0; } print:
printf("Please enter an operator (+, -, *, /):");
(void) scanf("%c",&op);
printf(" \t\t PLEASE ENTER THE TWO NUMBERS "); printf(" Type the First Number: "); (void) scanf("%f", &number1); printf(" Type the Second Number:"); (void) scanf("%f", &number2);
switch(op) { // Addition case '+': printf(" \t\t%.2lf + %.2lf = %.2lf", number1, number2, number1 + number2); break;
// Subtraction case '-': printf(" \t\t%.2lf - %.2lf = %.2lf", number1, number2, number1 - number2); break;
// Multiplication case '*': printf(" \t\t%.2lf * %.2lf = %.2lf", number1, number2, number1 * number2); break;
// Division case '/': printf(" \t\t%.2lf / %.2lf = %.2lf", number1, number2, number1 / number2); break;
default: printf("Error! You have not entered an operator "); } { again: printf (" Do you want to repeat the operation (Y/N): "); (void) scanf(" %c", &ch1);
if(ch1 == 'y' || ch1 == 'Y'){ goto print; } else if(ch1 == 'n' || ch1 == 'N'){ return 0; } }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started