lesson 6 mathvars cpp
[[lesson_6_mathvars_cpp]] last edit on
Aug 9, 2005
2:08 AM
by rescued_by_c
[user02@FC4 Lesson06]$ cat -n mathvars.cpp
[user02@FC4 Lesson06]$ ./mathvars
Item Cost: $15.5 Tax: $0.93 Total: $16.43
Customer change: $3.57
1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 float cost = 15.50; // The cost of an item
7 float sales_tax = 0.06; // Sales tax is 6 percent
8 float amount_paid = 20.00; // The amount the buyer paid
9 float tax, change, total; // Sales tax, buyer change and
10 // total bill
11
12 tax = cost * sales_tax;
13 total = cost + tax;
14 change = amount_paid - total;
15
16 cout << "Item Cost: $" << cost << "\tTax: $" << tax << "\tTotal: $" << total << endl;
17
18 cout << "Customer change: $" << change << endl;
19
20 return 0;
21 }
[user02@FC4 Lesson06]$ g++ -o mathvars mathvars.cpp[user02@FC4 Lesson06]$ ./mathvars
Item Cost: $15.5 Tax: $0.93 Total: $16.43
Customer change: $3.57