Starting over a primary loop from a secondary loop?

I am trying to put together a calculator program. So far I've got everything to work except for restarting the program if when the user is prompted to quit and he/she selects no, to restart my primary loop. Here is what I've got so far, any ideas!? Thanks!!

cout << "Let's Do a Calculation, Hit the ENTER key After Each Input" << endl ;
cout << "------------------------------------------------------------" << "\n" << endl ;
cout << "When Finished Calculating, Enter the Equal (=) Function" << endl << endl ;
//cout << "-------------------------------------------------------" << endl ;

cout << "Please Enter a Number ==> " ; // 1st input
cin >> input1 ;
cout << "Great Job!" << endl;

cout << "Please Enter ONE of the Provided Functions ( + - * / = ) ==> " ;
cin >> function ; // 1st function
cout << "Great Job!" << endl;

cout << "Please Enter Another Number ==> " ;
cin >> input2 ; // 2nd input
cout << endl ;
cout << "Great Job!"<< endl ;

if (function == '+' ) // if statement for particular function
{
sum1 = input1 + input2 ; // addition
runningtotal = sum1 ;
}
else if (function == '-' )
{
difference1 = input1 - input2 ; // subtraction
runningtotal = difference1 ;
}
else if (function == '*' )
{
product1 = input1 * input2 ; // multiplication
runningtotal = product1 ;
}
else if (function == '/' )
{
qoutient1 = input1 / input2 ; // division
runningtotal = qoutient1 ;
}

cout << "Current total is now: " << runningtotal << endl << endl ; //running total


while (function != '=') // beginning of while loop (to keep prompting until '=')

{

cout << "Please Enter a Function ( + - * / = ) ==> " ;
cin >> function ;

if (function == '=') // If statement breaking loop when '=' is inputed
break ;

cout << "Please Enter Another Number ==> " ;
cin >> input3 ; // additional inputs
cout << endl ;

if (function == '+' ) // if statement for particular function in loop
{
sum2 = runningtotal + input3 ; // addition
runningtotal = sum2 ;
}
else if (function == '-' )
{
difference2 = runningtotal - input3 ; // subtraction
runningtotal = difference2 ;
}
else if (function == '*' )
{
product2 = runningtotal * input3 ; // multiplication
runningtotal = product2 ;
}
else if (function == '/' )
{
qoutient2 = runningtotal / input3 ; // division
runningtotal = qoutient2 ;
}

cout << "Current total is now: " << runningtotal << endl << endl ;

} // end of loop




cout << "The Grand Total is: " << runningtotal << endl ;
cout << endl ;

cout << "Would you like to quit? (y or n) ==> " ;
cin >> quit ;

switch ( quit ) //switch
{
case 'y' :
case 'Y' :
cout << "Thanks for using Justin's Calculator!" << endl << endl ;
break ;
case 'n' :
case 'N' :
cout << "Then lets keep going!" << endl << endl ;


} // end of switch


return 0 ;
}
Topic archived. No new replies allowed.