Hello, I'm having issues with my final total for charges. When I run my program, it either comes up with "0" or if I don't declare my variable, it comes up with a long string of numbers. My total hours works great, but not my charges. Can someone take a look at my code and see if they see something I need to look at? I thought it was my setprecision or fixed, but it's not. Thanks
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
using std::fixed;
#include <iomanip>
using std::setw;
using std::setiosflags;
using std::setprecision;
#include <cmath>
//function prototype
double calculateCharge(double);
double Totalhours(double);
int count;
int total_hours;
int total_charge;
int main()
{
int num;
int charge;
int count = 1;
int total_hours = 0 ;
int total_charge = 0 ;
for( int i = 0; i < 3; ++i )
{
cout << "enter hours parked ";
cin >> num ;
cout<< setw(4)<< "CAR " << setw(20)<< "HOURS" << setw(18)<< "CHARGE\n";
cout<< count << setw(20)<< num << setw(18)<< fixed << setprecision( 2 ) << calculateCharge (charge) << endl;
charge = charge;
count = count + 1;
total_hours = total_hours + num;
total_charge = total_charge + charge;
}
cout<< setw(05)<< "TOTAL HOURS" << setw(10)<< total_hours << setw(16)<< fixed << setprecision( 2 ) << endl;
cout << fixed << setprecision( 2 );
cout<< setw(10)<< "TOTAL CHARGES"<< setw(10)<< total_charge << setw(16)<< endl;
cout<< setw(10)<< "TOTAL CHARGES"<< setw(10)<< charge << setw(16)<< endl;
return 0;
}//end main
double calculateCharge( double x)
{
double charge;
if (x <= 3)
charge = 2;
else if (x >19)
charge = 10;
else if (x > 3)
charge = 2 + (x - 3) * (.5);
return charge;
}