Question: how would i modify this code to read in information from a file and then output into a file #include #include #include int main() {

how would i modify this code to read in information from a file and then output into a file

#include #include #include int main() { char ch; float voltage , current , resistance , result, R1, R2;

printf("Choose from 1 to 6 from the following: "); printf("1.Ohm's Law To Find the voltage. "); printf("2.Ohm's Law To Find the current. "); printf("3.Ohm's Law To Find the resistance. "); printf("4.Voltage Divider To find the voltage accros R1. "); printf("5.Voltage Divider To find the voltage accros R2. "); printf("6.Current Divider To find the Current passing through R1. "); printf("7.Current Divider To find the Current passing through R2. "); printf("Anything else to quit. ");

scanf("%c",&ch); switch(ch) { case '1' : printf("Current Value? "); scanf("%f",¤t); printf("Resistance Value? "); scanf("%f",&resistance); result = current * resistance; printf("The voltage is %0.2f V. ",result); break; case '2' : printf(" voltage value? "); scanf("%f",&voltage); printf("Resistance value? "); scanf("%f",&resistance); result = voltage / resistance; printf("The current is %0.2f A. ",result); break; case '3' : printf("voltage value? "); scanf("%f",&voltage); printf("current Value? "); scanf("%f",¤t); result = voltage / current; printf("The resistance is %0.2f ohms. ",result);

case '4' : printf("R1 Value? "); scanf("%f",&R1); printf("R2? "); scanf("%f",&R2); printf("Voltage Value? "); scanf("%f",&voltage); result = R1*voltage/(R1+R2); printf("The voltage is %0.2f V. ",result); break;

case '5' : printf("R1 Value? "); scanf("%f",&R1); printf("R2? "); scanf("%f",&R2); printf("Voltage Value? "); scanf("%f",&voltage); result = R2*voltage/(R1+R2); printf("The voltage is %0.2f V. ",result); break; case '6' : printf("R1 Value? "); scanf("%f",&R1); printf("R2 value? "); scanf("%f",&R2); printf("current Value? "); scanf("%f",¤t); result = R2*current/(R1+R2); printf("The current is %0.2f A. ",result); break; case '7' : printf("R1 Value? "); scanf("%f",&R1); printf("R2 Value? "); scanf("%f",&R2); printf("current Value? "); scanf("%f",¤t); result = R1*current/(R1+R2); printf("The current is %0.2f A. ",result); break; break; default : exit(0); return 0;} 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!