Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 int main() { char op, ch, ch1; float number1, number2;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

What is a process chain?

Answered: 1 week ago