需要帮助来声明“现金”的价值。

时间:2014-02-12 03:33:15

标签: c++

它在说明中说“你可以假设现金等于或大于总账单”。如何申报现金价值并使其大于或等于总账单?我对“更改”“totalBill”变量的声明是否正确?我真的需要一些帮助,就像我说这是我的第一次。

#include <iostream>
#include <iomanip>
using namespace std;

const double CHILDPRICE = 10.00;
const double ADULTPRICE = 20.50;

int main ()
{   

double adultTotal, childTotal, totalBill, change;
int childTix, adultTix, cash;



cout << "\n           Chesapeake Amusement Park" << endl << endl;

cout << "    Enter children tickets... ";
cin >> childTix;    
cout << "    Enter adult tickets...... ";
cin >> adultTix;

childTotal = CHILDPRICE * childTix;
adultTotal = ADULTPRICE * adultTix;
totalBill = childTotal + adultTotal;
change = cash - totalBill;

//The following is a sample of how you can format the output
//childTix is an integer variable
//CHILDPRICE is a double const
//childTotal is a double variable

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "\n\n                 Chesapeake Amusement Park";
cout << "\n                 -------------------------";
cout << "\n\n               Tickets      Price      Total\n";

cout << "     Children   " << setw(3)  << childTix  
                           << setw(14) << CHILDPRICE 
                           << setw(11) << childTotal;

cout << "\n     Adults     " << setw(3)  << adultTix  
                             << setw(14) << ADULTPRICE 
                             << setw(11) << adultTotal;

cout << "\n ";
cout << "\n ";
cout << "\n     Total Bill                  " << setw(11) << totalBill;


//Place remaining input/output statements here
cout << "\n ";
cout << "\n ";
cout << "\n        Cash recieved...... ";
cin >> cash;

cout << "\n ";
cout << "\n ";
cout << "\n     Change                  " << setw(4) << change;

return 0;

}

0 个答案:

没有答案