PDA

View Full Version : Issues with double variables in c++ 2011



Vuhelper
06-12-2011, 07:26 PM
1.
#include <iostream>
2.
#include <iomanip>
3.
using namespace std;
4.

5.
void printbill(double kwhused, double rate, double charge, double tax, double total)
6.
{
7.
// Print Logo
8.
cout << "pppppp oooooo w w w eeeeeeee rrrrrrr cccccc oooooo" << endl;
9.
cout << "p p o o w w w e r r c c o o" << endl;
10.
cout << "p p o o w w w e r r c o o" << endl;
11.
cout << "pppppp o o w w w eeeeee rrrrrrr c o o" << endl;
12.
cout << "p o o w w w e r r c o o" << endl;
13.
cout << "p o o w w w e r r c o o..." << endl;
14.
cout << "p o o w w w w e r r c c o o..." << endl;
15.
cout << "p oooooo w w eeeeeeee r r cccccc oooooo ..." << endl << endl;
16.

17.
// Print column headers
18.
cout << setw(10) << "KW/H Used" << setw(10) << "Rate" << setw(10) << "Charge" << setw(10) << "Tax" << setw(10) << "Total";
19.

20.
// Print data
21.
cout << setw(10) << kwhused << setw(10) << rate << setw(10) << charge << setw(10) << tax << setw(10) << total << endl << endl;
22.
}
23.

24.
int main()
25.
{
26.
// Declare constant variables(rate, taxrate)
27.
const double rate = .001;
28.
const double taxrate = .05;
29.

30.
// Declare variables
31.
double charge, kwhused, total, tax;
32.

33.
// Get kw/hr use
34.
cout << "Please input number of kilowatts used : " << endl << endl;
35.
cin >> kwhused;
36.
cout << endl << endl << endl;
37.

38.
// Calculate charge
39.
charge = rate * kwhused;
40.

41.
// Calculate tax
42.
tax = charge * taxrate;
43.

44.
// Calculate total
45.
total = tax + charge;
46.

47.
// Call the printbill() function
48.
printbill(kwhused, rate, charge, tax, total);
49.

50.
return 0;
51.
}
http://https//secure.gravatar.com/avatar/7104665aae2b28ca04d52c447c302540?s=140&d=https://d3nwyuy0nl342s.cloudfront.net%2Fimages%2Fgravatars %2Fgravatar-140.png