Hello,
I'm writing a program for class that holds information from a parking garage and calculates the cost of parking for each vehicle and the total revenue generated. The code I've written uses a struct Car which contains variables for Tag#(string)
, Make(string)
, Cost(int)
, Time in(int b/w 1 & 24)
, and Time out(int b/w 1 & 24)
. I'm having trouble doing some simple math to calculate the cost for a single car. I'm apparently having trouble with declaring my variable and the way I'm stating the variables inside of the equation.
Also my function protoype is returning a link error
Any help would be greatly appreciated seeing that this is due tomorrow.
I've highlighted the lines that I'm having issues with.
Here is the error message I'm receiving:
error C2228: left of '.Cost' must have class/struct/union type
Here's the code:
/***************************************************
* Author: Robert McGahee Date: 6/15/09 *
* Program: Parking Garage Project *
* This program takes the tag numberand the make *
* of a vehicle and calculates the time that it *
* was in the parking garage and bills the car *
* $10 for the first hour and $5 for every hour *
* afterwards. It also diplays the total made by *
* the garage for the day. *
*-------------------------------------------------*
* This syntax is the intellectual property of *
* the author. You may use the code and modify it,*
* as far as this header remains intact. *
* In no way shall the author be liable for any *
* losses or damages resulting from the use of this*
* program. Use AS-IS at your own risk. *
***************************************************/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int Total(struct Car Carlist[],int Cost,int i1);
struct Car
{
string Tag;
string Make;
int Time_in;
int Time_out;
int Cost;
};
int main()
{
Car Carlist[100];
int i1;
int i;
int Revenue;
char Answer;
Answer='Y';
i1=0;
cout<<"****************************"<<endl;
cout<<"* WELCOME TO THE GARAGE *"<<endl;
cout<<"****************************"<<endl;
system("pause");
while(Answer=='Y'||Answer=='y')
{
system("cls");
cout<<"Please enter the tag number: ";
cin>>Carlist[i1].Tag;
cout<<"Please enter the make of the car: ";
cin>>Carlist[i1].Make;
cout<<"Please enter the hour (1-24) they entered the garage: ";
cin>>Carlist[i1].Time_in;
cout<<"Please enter the hour (1-24) they left the garage: ";
cin>>Carlist[i1].Time_out;
Carlist.Cost[i1]=(Carlist.Time_out[i1]-Carlist.Time_in[i1])*5+5;
cout<<"Would you like to enter another car's information? (Y/N): ";
cin>>Answer;
if(Answer=='y'||Answer=='Y')
i1++;
}
Revenue=Total(Carlist,i1,Cost);
cout<<setfill(' ')<<left<<setw(10)<<" Tag #"<<right<<setw(15)<<"Make"<<right<<setw(8)<<"Time in"<<right<<setw(9)<<"Time out"<<right<<setw(5)<<"Cost"<<endl;
for(i=0;i<=i1;i++)
{
cout<<setfill(' ')<<left<<setw(10)<<Carlist[i].Tag<<right<<setw(15)<<Carlist[i].Make<<right<<setw(8)<<Carlist[i].Time_in<<right<<setw(9)<<Carlist[i].Time_out<<right<<setw(5)<<"$ "<<Carlist[i].Cost<<endl;
}
cout<<endl;
cout<<setfill(' ')<<left<<setw(33)<<"Total Cars"<<i1<<right<<setw(14)<<"Total Revenue"<<Revenue<<endl;
system("pause");
return 0;
}
int Total(Car Carlist[],int Cost, int i1)
{
int i;
int Tot_Cost;
Tot_Cost=0;
for(i=0;i<=i1;i++)
{
Tot_Cost=Carlist[i].Cost+Tot_Cost;
}
return Tot_Cost;
}
Thank you.