Error variable not initialized? WTF

#include <iostream>
using namespace std;


int main()
{
double meal_cost,
tax = 0.0935,
tip = .18;
int Tax_MC,
bill,
total_bill,
Tip_TB;

//Find out cost of meal
cout << "Enter the cost of the meal before tip and tax" << meal_cost << endl;
cin >> meal_cost;

//Calculate the tax of the meal cost
Tax_MC = meal_cost * tax;

//Calculate the amount of the bill
bill = Tax_MC + meal_cost;

//Calculate the cost of the tip from bill
Tip_TB = bill * tip;

//Calculate the total amount of the bill plus tip
total_bill = bill + Tip_TB;

//Display the results
cout << "The meal cost came up to $" << meal_cost <<" without tax" << endl;
cout << "The tax amount of the meal cost is $" << Tax_MC << endl;
cout << "The tip came up to $" << Tip_TB << endl;
cout << "The amount of the bill plus tip is $" << total_bill << endl;
system("pause");
return 0;
}


This error keeps coming up.....

The variable "meal_cost" is being used with out being initialized


Please help....
It is not intialized because you didn't initialize it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;


int main()
{
double meal_cost,
tax = 0.0935,
tip = .18;
int Tax_MC,
bill,
total_bill,
Tip_TB;

//Find out cost of meal
cout << "Enter the cost of the meal before tip and tax" << meal_cost << endl;
cin >> meal_cost;

//Calculate the tax of the meal cost
Tax_MC = meal_cost * tax;

//Calculate the amount of the bill
bill = Tax_MC + meal_cost;

//Calculate the cost of the tip from bill
Tip_TB = bill * tip;

//Calculate the total amount of the bill plus tip
total_bill = bill + Tip_TB;

//Display the results
cout << "The meal cost came up to $" << meal_cost <<" without tax" << endl;
cout << "The tax amount of the meal cost is $" << Tax_MC << endl;
cout << "The tip came up to $" << Tip_TB << endl;
cout << "The amount of the bill plus tip is $" << total_bill << endl;
system("pause");
return 0;
}

This is your program.

Line 16: you print the variable meal_cost, which is a double, without initialize it. You have just to write:
1
2
cout << "Enter the cost of the meal before tip and tax"<< endl;
cin >> meal_cost;


See if it works now.
Last edited on
Topic archived. No new replies allowed.