Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

Question Can employees make contributions to a profit sharing plan?

Answered: 1 week ago