Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!