- Apr 1, 2001
- 1,427
- 0
- 0
I am supposed to use a while and switch structure for one of my assignments. My question is after one of the cases are met, how do I get it to go back to beginning of the program to prompt for new input? Any help is appreciated.
while(Sel == 1 || Sel == 2 || Sel == 3)
{
switch(Sel)
{
case 1:
float R1, R2, R3, rsum, curr;
cout << "Three resistor series circuit selected " << endl;
cout << "Enter Value for R1 (Ohms) : " << endl;
cin >> R1;
cout << "Enter Value for R2 (Ohms) : " << endl;
cin >> R2;
cout << "Enter Value for R3 (Ohms) : " << endl;
cin >> R3;
rsum = R1 + R2 + R3;
curr = volt / rsum;
cout << endl << endl;
cout << "Three resistor parallel circuit selected " << endl << endl;
cout << "Voltage across R1 = " << curr * R1 << endl;
cout << "Voltage across R2 = " << curr * R2 << endl;
cout << "Voltage across R3 = " << curr * R3 << endl << endl;
cout << "Current through R1 = " << volt << endl;
cout << "Current through R2 = " << volt << endl;
cout << "Current through R3 = " << volt << endl;
return 0;
break;
case 2:
cout << "Enter Value for R1 (Ohms) : " << endl;
cin >> R1;
cout << "Enter Value for R2 (Ohms) : " << endl;
cin >> R2;
cout << "Enter Value for R3 (Ohms) : " << endl;
cin >> R3;
cout << endl;
cout << "Voltage across R1 = " << volt << endl;
cout << "Voltage across R2 = " << volt << endl;
cout << "Voltage across R3 = " << volt << endl << endl;
cout << "Current through R1 = " << volt / R1 << endl;
cout << "Current through R2 = " << volt / R2 << endl;
cout << "Current through R3 = " << volt / R2 << endl;
break;
case 3:
return 0;
break;
while(Sel == 1 || Sel == 2 || Sel == 3)
{
switch(Sel)
{
case 1:
float R1, R2, R3, rsum, curr;
cout << "Three resistor series circuit selected " << endl;
cout << "Enter Value for R1 (Ohms) : " << endl;
cin >> R1;
cout << "Enter Value for R2 (Ohms) : " << endl;
cin >> R2;
cout << "Enter Value for R3 (Ohms) : " << endl;
cin >> R3;
rsum = R1 + R2 + R3;
curr = volt / rsum;
cout << endl << endl;
cout << "Three resistor parallel circuit selected " << endl << endl;
cout << "Voltage across R1 = " << curr * R1 << endl;
cout << "Voltage across R2 = " << curr * R2 << endl;
cout << "Voltage across R3 = " << curr * R3 << endl << endl;
cout << "Current through R1 = " << volt << endl;
cout << "Current through R2 = " << volt << endl;
cout << "Current through R3 = " << volt << endl;
return 0;
break;
case 2:
cout << "Enter Value for R1 (Ohms) : " << endl;
cin >> R1;
cout << "Enter Value for R2 (Ohms) : " << endl;
cin >> R2;
cout << "Enter Value for R3 (Ohms) : " << endl;
cin >> R3;
cout << endl;
cout << "Voltage across R1 = " << volt << endl;
cout << "Voltage across R2 = " << volt << endl;
cout << "Voltage across R3 = " << volt << endl << endl;
cout << "Current through R1 = " << volt / R1 << endl;
cout << "Current through R2 = " << volt / R2 << endl;
cout << "Current through R3 = " << volt / R2 << endl;
break;
case 3:
return 0;
break;