I have written a program that accepts inputs for resistors in series and a program that will accept resistor values that are connected in parallel. On the menu to select series I used "1" and to select parallel I use "2". I did a printf on to make sure the math is applied correctly and indeed the formulas are correctly working.
The problem I am having is escaping out of a loop using the enter key, when I am done entering resistor values. After getting out of the loop be pressing the enter key, it should display the final value. I then wanted to use enter again to get me back to the main option menu.
Here is my pseudo code is:
Begin display of option menu for series or parallel
Enter values, when finished press enter to display final value
To get back to the main option menu, press enter again
Here is my actually code:
Code:
/*
*====================================================================
*
*
*
*
*
*
*
*Written by: Dennis Reece
*====================================================================
*/
#include <stdio.h>
#include <math.h>
int main(void)
{
float rrecip=0; (reciprocal of R)
int option;
int ir = 1; /* ir is the counter for R1.....Rn */
float rinput=0, rtotal=0; /*rinput is the resistor value in ohms; and rinput is initially set to 1 to make the while
statement true allowing the loop to function*/
printf(" Type in 1 for seires or 2 for parallel\n ");
/*scanf("%i", &rcount);
for(ir=1; ir<=rcount; ir = ir+1)*/
scanf("%c" , &option);
switch (option)
{
case 1:
while(rinput== exit)
{
/*series*/
printf("R%i=" , ir); /*appends resistor number to R */
scanf("%f", &rinput);/*Resistor ohm value input; and overrides rinput=1 from declaration above */
printf("\n");
rtotal = rtotal + rinput;
ir = ir+1; /*increments the resistor R number by 1*/
}
case 2:
while(rinput == exit)
{
/*parallel*/
printf("R%i=", ir);
scanf("%f", &rinput);
printf("\n");
rrecip = rrecip+(1/rinput);
ir = ir+1;
printf("%f" , rrecip);
}
rtotal= 1/rrecip;
}
printf("%f", rtotal);
}