Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i create this code to make basic operation but i want to add more when the user enter a invalis input like a letter print

i create this code to make basic operation but i want to add more when the user enter a invalis input like a letter

print invalid input basically i need a invalid function

#include float addTwo( float A, float B ); float RestTwo( float A, float B ); float MultiplyTwo( float A, float B ); float DivideTwo( float A, float B );

int main() { float x, y ,z , i; // lets store some stuff x=0; // set some arbitrary values y=0; z=0;

printf("Welcome to calculator "); printf("This calculator only sum = 1, rest = 2, multiply = 3 and divide = 4. ");

i > 0; while (i>0) { printf("Please enter first the numbers then the operand you want to use. "); scanf("%f %f", &x,&y); scanf("%f", &i); if (i>=4) { z = DivideTwo (x,y); printf("The division of %f and %f is: %f ", x, y, z) ; }

else if (i >= 3){ z = MultiplyTwo(x,y); printf("the multiplication of %f and %f is: %f ", x, y, z); }

else if (i >=2){ z = RestTwo(x,y); printf("the rest of %f and %f is: %f ", x, y, z);

} else if (i>=1){ z = addTwo(x,y); printf("the sum of %f and %f is: %f ", x, y, z); } else { printf("invalid input. "); }

}

return 0; }

// this function will add two floats together float addTwo( float A, float B ) { float sum; // create a new variable to store the sum of our variables sum = A + B; // do the math for our summing return sum; // give the result back to the "calling function"

return A+B ; } float RestTwo( float A, float B ) { float sum; // create a new variable to store the sum of our variables sum = A - B; // do the math for our subtracting return sum; // give the result back to the "calling function"

return A- B; } float MultiplyTwo( float A, float B ) { float sum; // create a new variable to store the sum of our variables sum = A * B; // do the math for our multiplying return sum; // give the result back to the "calling function"

return A* B; } float DivideTwo( float A, float B ) { float sum; // create a new variable to store the sum of our variables sum = A / B; // do the math for our dividing return sum; // give the result back to the "calling function"

return A/B; }

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

=+ d. Income per worker in Richland is actually

Answered: 1 week ago