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