Question: i have this C-program, how can i set it so the input values can not be greater than 1000? and if the user inputs a

i have this C-program, how can i set it so the input values can not be greater than 1000? and if the user inputs a value of 1000 or higher it should come up with an error message in the output?

#include int main(void) { double p,i,r; //initialise variables int fl=-1; //initialise flag variable to be -1 printf("Enter P, I and R:"); scanf("%lf %lf %lf",&p,&i,&r); //input the 3 double variables if(p==0 && i>0 && r>0) //check if p is 0 and others greater than 0 fl=0; //set flag else if(i==0 && p>0 && r>0) //check if i is 0 and others greater than 0 fl=1; //set flag else if(r==0 && p>0 && i>0) //check if r is 0 and others greater than 0 fl=2; //set flag else //if wrong input fl=-1; //set flag if(fl==0) printf("Power P : %.3lf",i*i*r); //print power else if(fl==1) printf("Current I : %.3lf",sqrt(p/r)); //print current else if(fl==2) printf("Resistance R : %.3lf",p/(i*i)); //print resistance else { printf("Invalid input."); //print invalid return -1; } return 0; }

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!