Wie man Benutzereingaben in eine do/while-Schleife?

Ich habe versucht, die do /while-Schleife fragte ich und Feste in meine eine Funktion in int main zu ermöglichen, das gesamte Programm erneut ausgeführt werden, wenn der Benutzer dies wünscht, aber es ist erneutes ausführen des Programms, ohne auf Benutzereingaben warten.

int main()
{
    int spoolnumber = 0;     //Number of spools to be ordered
    float subtotalspool = 0; //Spool sub total
    float shippingcost = 0;  //Shipping cost
    float totalcost = 0;     //Total cost
    char type = 'n';

    do {
        instruct();                     //Print instructions to user
        spoolnumber = spoolnum();       //calculate and store number of spools

        subtotalspool = stotalspool(spoolnumber);       //Calculate subtotal
        shippingcost = shipcost(subtotalspool);         //Calculate subtotal
        totalcost = tcost(subtotalspool, shippingcost); //Calculate final total

        //Print final output
        results(spoolnumber, subtotalspool, shippingcost, totalcost);     
        cout << "\n" << " Would you like to run the program again? [y/n]"; 
    }
    while (type != 'y');

    return 0;
}
InformationsquelleAutor Sam LaManna | 2011-10-17
Schreibe einen Kommentar