Making a Bill

I'm supposed to be making a bill and it went well up until i needed to have taxes added to the bill and I also ended up being required to use minutes instead of hours for the unit of time And I can't seem to get either to work out right. It keeps telling me that Total hasn't been initialized
<

// This program will calculate the charge of getting surfing lessons including cost of equipment, hourly rate, tax, and a tip.

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

const float TAX_RATE = 0.04f;
const int TITLE_COLUMN_WIDTH = 15;
const int AMOUNT_COLUMN_WIDTH = 10;



int main (void)

{
//// 1.0 Instruct User ////
cout << " Star-Surf Surf Lessons Bill Generator " << endl;
cout << endl;
cout << "Please enter values when prompted:" << endl;

//// 2.0 Surf Lesson Total Generator ////

//// 2.1 User Inputs Values ////



float equipmentFee;
cout << "Equipment Rental Fee: "; cin >> equipmentFee;
cin.ignore(999,'\n');

if ( cin.fail() )
{
cin.clear();
cin.ignore(999,'\n');
cout << "Invalid Input. Terminating Program." << endl;
cout << "Press ENTER to finish...";
cin.ignore(999,'\n');
return 1;
}

if ( equipmentFee < 0)
{
cout << "Negative values are not allowed. Terminating program." << endl;
cout << "Press ENTER to continue..." << endl;
cin.ignore(999,'\n');
return 1;
}

float hourlyRate;
cout << "Instructor's Hourly Rate: "; cin >> hourlyRate;
cin.ignore(999,'\n');

if ( cin.fail() )
{
cin.clear();
cin.ignore(999,'\n');
cout << "Invalid Input. Terminating Program." << endl;
cout << "Press ENTER to finish...";
cin.ignore(999,'\n');
return 1;
}

if ( hourlyRate < 0)
{
cout << "Negative values are not allowed. Terminating program." << endl;
cout << "Press ENTER to continue..." << endl;
cin.ignore(999,'\n');
return 1;
}

if ( hourlyRate == 0)
{
cout << "Error encountered. Terminating Program." << endl;
cout << "Press ENTER to continue..." << endl;
cin.ignore(999,'\n');
return 1;
}

int minutesInstructed;
cout << "Total Minutes of Instruction: "; cin >> minutesInstructed;
cin.ignore(999,'\n');

if ( cin.fail() )
{
cin.clear();
cin.ignore(999,'\n');
cout << "Invalid Input. Terminating Program." << endl;
cout << "Press ENTER to finish...";
cin.ignore(999,'\n');
return 1;
}

if ( minutesInstructed < 0)
{
cout << "Negative values are not allowed. Terminating program." << endl;
cout << "Press ENTER to continue..." << endl;
cin.ignore(999,'\n');
return 1;
}

if ( minutesInstructed == 0)
{
cout << "Cannot charge for zero hours instructed. Terminating Program." << endl;
cout << "Press ENTER to continue..." << endl;
cin.ignore(999,'\n');
return 1;
}



//// 2.2 Total is Generated ////


float total;
((hourlyRate * minutesInstructed) + equipmentFee);

float taxes = total * TAX_RATE;

float subTotal;
cout << "Your total is: " << total + taxes << endl;

//// 3.0 Surf Lesson Bill Generator ////

//// 3.1 Prompt User for Tip ////
int main1 (void);
{
float tip;
cout << "Please enter your tip: "; cin >> tip;
cin.ignore(999,'\n');


//// 3.2 Complete Bill is Generated////
cout << endl;
cout << " ============================================================== " << endl;
cout << "Lesson Bill " << endl;
cout << endl;

cout << setw ( TITLE_COLUMN_WIDTH)
<< left
<< " Equipment Rental Fee "
<< setw (AMOUNT_COLUMN_WIDTH)
<< right
<< setprecision (2);
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << equipmentFee
<< endl;

cout << setw ( TITLE_COLUMN_WIDTH)
<< left
<< " Instruction Fee "
<< setw (AMOUNT_COLUMN_WIDTH)
<< right
<< setprecision (2);
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << hourlyRate
<< endl;

cout << setw ( TITLE_COLUMN_WIDTH)
<< left
<< " Service Tax "
<< setw (AMOUNT_COLUMN_WIDTH)
<< right
<< setprecision (2);
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << taxes
<< endl;

cout << setw ( TITLE_COLUMN_WIDTH)
<< left
<< " Tip "
<< setw (AMOUNT_COLUMN_WIDTH)
<< right
<< setprecision (2);
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << tip
<< endl;
cout << ---------- << endl;

cout << setw ( TITLE_COLUMN_WIDTH)
<< left
<< " Total Bill "
<< setw (AMOUNT_COLUMN_WIDTH)
<< right
<< setprecision (2);
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << subTotal
<< endl;

cout << " ============================================================== " << endl;
cout << endl;

if ( tip < ( subTotal * 0.15))
cout << "Ohhhhhh!!! Big Spender!!!! -_-" ;
else if ( tip > ( subTotal * 0.15 ))
cout << "Thank you for coming" ;
else if (tip > (subTotal * 0.20 ))
cout << "Please come again soon!" ;
}

//// 4.0 Endgame ////
cout << endl;
cout << "Press ENTER to continue..." << endl;
cin.ignore(999,'\n');
return 0;



}
>
Last edited on
You can't cin to an expression:
 
cin >> ((hourlyRate * minutesInstructed) + equipmentFee);


Did you mean:
 
  total = ((hourlyRate * minutesInstructed) + equipmentFee);


BTW, that's going to cause a scaling problem. 30 minutes * an hourly rate of $10 = $150, when you want a result of $5.

 
cout << "Your total is: " << Total + (Total * TAX_RATE) << endl;

The compiler is correct. You never stored anything into Total. See the comment above regarding cin.

 
float TAX_RATE;

That's going to hide the global constant by the same name.


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Topic archived. No new replies allowed.