lundi 19 septembre 2016

Calculating if statement not working c++

so I got this code and put in the comments of the code what the problem is (at the end of while loop). Cant figure it out some help would be lovely. Code is quite long, tips to shorten it would be more than welcome as well! :) Thanks already!

system("cls");

int people = 0;
int total = 0;
char ok;
double priceu16 = 2.5;
double pricea65 = 3;
double priceothers = 5;
double u16 = 0;
double a65 = 0;
double others = 0; 
double totalprice = 0;
double totalu16, totala65, totalothers;
double discount = 0.80; 
cout << "The admission fees for the swimming pool are: \n";
cout << "\nUnder 16's: 2.50 \n";
cout << "Over 65: 3.00 \n"; 
cout << "All other swimmers: 5.00 \n";
cout << "A 20% discount for groups of 6 people or more! \n";
cout << ".............................................. \n";
cout << "\nEnter the age of the people (then press enter) and -1 when finished: \n";

while (people != -1) {
    cin >> people;
    if (people > 0 && people < 16) {
        u16 = u16 + 1; 
        total++;    
    }
    else if (people > 65) {
        a65 = a65 + 1;
        total++;
    }
    else if (people > 15 && people < 66)  {
        others = others + 1;
        total++;
    }
    else { }
    }

if (total >= 6) {
    totalprice * discount; // This should calculate a 20% discount if total is either 6 or more, but its not working.    << problem.... 
}
cout << "\nYou are with " << total << " people. \n";

cout << "\nIs this correct? [Y] Yes [N] No : "; //user input to continue otherwise back to start.
cin >> ok;
if (ok == 'N' || ok == 'n' || ok == 'No') {
    return main();          }

totalu16 = u16 * priceu16; 
totala65 = a65 * pricea65;
totalothers = others * priceothers; 
cout << "\nUnder 16 is: " << u16 << "   (" << totalu16 << " pounds)\n"; 
cout << "\nAbove 65 is: " << a65 << "   (" << totala65 << " pounds)\n"; 
cout << "\nOthers   is: " << others << "   (" << totalothers << " pounds)\n"; 

totalprice = totalprice + totalu16 + totala65 + totalothers; 

cout << "\nThis makes a total of: " << totalprice << " pounds"; 

    cin.get(); //both cin to keep showing the output window. 
    cin.get(); 

return 0;

}

Aucun commentaire:

Enregistrer un commentaire