My assignment is to create a program that has 3 options:
a) add in series
b) add in parallel
c) quit
So far this is what I have. However, I'm stuck in the parallel function, I can not figure it out why I cant divide(tried multiplying but I am not able to either) and output the result. I have tried making my variables floats, converting integers to variables, using gets() instead of scanf. It will not even print "sum = u_input;" but when I added with sum like in the series() It will print out the result. Whatever I do It keeps printing out 0 as a total. I am obviously missing a huge detail (oxymoron?). If I am missing any info that would make the debugging any easier please let me know
-Antonio
Code:
#include <stdio.h>
#include <stdlib.h>
series()
{
int u_input = 0;
int v_counter = 0;
int sum = 0;
do
{
printf("Enter resistor %d value, 0 to calculate: ", v_counter += 1);
scanf("%d", &u_input);
sum = sum + u_input;
}while(u_input != 0);
printf("\n\nThe sum of the resistor in series is: %d\n\n", sum);
system("pause"); //scanf y poner enter any letter to continue would probly be more elegant
main();
}
parallel()
{
int u_input = 0;
int v_counter = 0;
int sum = 0;
do
{
printf("Enter resistor %d value, 0 to calculate:", v_counter += 1);
scanf("%d", &u_input);
sum = u_input; //PROBLEM
}while(u_input != 0);
printf("\n\nThe sum of the resistor in parallel is: %d\n\n", sum);
system("pause"); //scanf y poner enter any letter to continue would probly be more elegant
main();
}
menu()
{
char choice;
for(;;)
{
system("cls");
printf("This program will calculate resistance value in either series or parallel\n\n");
printf("1) Calculate in series\n");
printf("2) Calculate in parallel\n");
printf("q) quit program\n");
choice = getchar();
switch(choice)
{
case '1':
system("cls");
series();
break;
case'2':
system("cls");
parallel();
break;
case'q':
case'Q':
system("cls");
main();
break;
}
}
}
int main()
{
menu();
return(0);
//Code::Blocks IDE has built in function that prevents screen from closing when program has been terminated
}