//6.12

#include <iostream>
#include <iomanip>

using namespace std;

double CalculateCharges (double car1=1.5,double car2=2.0,double car3=24.0);

int main ()

{




cout<<" Parking Garage Rates " << endl;

cout<<setw(10);
cout<<"Car"<<"Hours"<<"Charge"<<endl;

double car1;
for (int i=1;i<=3;i++)
cout<<i<<CalculateCharges(car1)<<endl;

cout<<"Total"<<endl;

return 0;

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


double CalculateCharges(double car1, double car2, double car3)
{
    double rate;
    double hours[3];
    hours[0]=car1;
    hours[1]=car2;
    hours[2]=car3;
    int b;
    for( b = 0; b <= 3; b++ ){
   hours[b] = b;
   }
    for (double h=0;h<=24;h=+hours[b])
    {
    if (h<=3)
    rate = 2.00;
    else if (h>=3)
    {
    rate = (.50*h);
    }
    else if ( h == 24 )
    {
    rate = 10.00 ;
    }
    
    

}
}

So the thing complies, but it does not generate any numbers, or anything like that.. I'm confused.. help.

hours[0]=car1;
hours[1]=car2;
hours[2]=car3;
int b;
for( b = 0; b <= 3; b++ )
   hours[b] = b;

Why are you bothering to assign values to hours in the first three lines if you are just going to overwrite them in the loop?
The loop tries to enter 4 values int hours, but hours can only hold 3. Therefore you overwrite the array, and hopefully crash your program.

2) At the end of the above loop b == 4. You then try to use b in the following line as an index for hours, eventhough it is well out of bounds as an index.
for (double h=0;h<=24;h=+hours)
Hopefully your program crashes when you try to do this.

3) what happens if h == 3 is the rate 2.00 or .50 * 3. Your logic says it's both, though I doubt that's what you want.

4) What if h is 24? Do you want the rate to be .50 * 3 or 10.00. Your logic says it's both, since it will be both >= 3 and == 24.

5) Where's the return statement to return a value from calculateCharges? It will be hard to output the return value in main() if you don't send anything back.

//6.12

#include <iostream>
#include <iomanip>

using namespace std;

double CalculateCharges (double car1=1.5,double car2=2.0,double car3=24.0);

int main ()

{




cout<<" Parking Garage Rates " << endl;


cout<<"Car"<<"Hours"<<"Charge"<<endl;

double rate
;
for (int i=1;i<=3;i++)
cout<<i<<" "<<CalculateCharges(rate)<<endl;

cout<<"Total"<<endl;

return 0;

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


double CalculateCharges(double car1, double car2, double car3)
{
    double hours[3];
     hours[0]=car1;
    hours[1]=car2;
    hours[2]=car3;
    int b;
    for( b = 0; b <= 2; b++ ){
   hours[b] = (hours[0],hours[1],hours[2]);
   }
    double rate;
    
   
   
    for (double h=0;h<=24;h=+hours[b])
    {
    if (h<3)
    rate = 2.00;
    else if (h>3)
    {
    rate = (.50*h);
    }
    else if ( h == 24 )
    {
    rate = 10.00 ;
    }
    
  return rate;  

}
}

Hello I tried to change some things like you said but it still did not work. I am pretty terrible at c++ so if you can explain once again what's wrong that would be super.

The program is supposed to loop 3 times, each time returning a rate based on the value i sent it from the function call at the top. But it's not doing that.. not at all. Each time it loops it's supposed to read the next value in the array.. Though that's not working either.

#include <iostream>
#include <iomanip>

using namespace std;

double CalculateCharges (double car1=1.5,double car2=2.0,double car3=24.0);

int main ()

{




cout<<" Parking Garage Rates " << endl;


cout<<"Car"<<"Hours"<<"Charge"<<endl;

// double rate
for (int i=1;i<=3;i++)
cout<<i<<" "<<CalculateCharges()<<endl;

cout<<"Total"<<endl;

return 0;

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


double CalculateCharges(double car1, double car2, double car3)
{
    double hours[3];
     hours[0]=car1;
    hours[1]=car2;
    hours[2]=car3;
    int b;
double rate =0;
    for( b = 0; b <= 2; b++ ){
   hours[b] += (hours[0]+hours[1]+hours[2]);
   
    
    
   
   

    for (double h=0;h<=24;h+=hours[b])
    {
    if (h<3)
    rate = 2.00;
    else if (h>3)
    {
    rate = (.50*h);
    }
    else if ( h == 24 )
    {
    rate = 10.00 ;
    }
   } 
  return rate;  

}
}
double cars[3];
cars[0] = 1.5;
cars[1] = 2.0;
cars[2] = 24.0;
for(int i = 0; i < 3;  ++i)
  cout << calculateCharges(cars[i]) << endl;

double calculateCharges(double car)
{
    if(car < 3)
       charge = whatever
   else if(car >= 3 && car < 24)
       charge = whatever
   else 
       charge = whatever
   return charge
}
const int SIZE = 3;
double cars[SIZE];
for(int i = 0; i < SIZE; i++)
   cars[i] = calculateCharges();

doule calculateCharges()
{
    cout << "enter hours"
    int hours;
    if(hours < 3)
    //etc
This article has been dead for over six months. Start a new discussion instead.