|
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have class/struct/union type.The problem area is underlined. Any help will be greatly appreciated. - #include <c:\cpp\input.h>
-
#include < time.h>
-
-
#define SIZE 20
-
-
struct Cust{
-
int custno;
-
char fname[16];
-
char surname[16];
-
char street[26];
-
char town[16];
-
char postcode[9];
-
char areacode[5];
-
char phoneno[6];
-
char rentaltype;
-
int noofpeople;
-
float rentalcost;
-
float electricalcost;
-
float total;
-
char rent;
-
-
};
-
-
-
void StartMenu(int &option);
-
void DisplayMenu1();
-
void DisplayTown(Cust record[],int count);
-
void EnterDetails(Cust record[], int &count);
-
void EnterCust(Cust &record);
-
void CalcRentalCost (Cust &record);
-
void DisplayDetails(Cust record[],int count);
-
void DisplayCustomer(Cust record);
-
void CalculateAverage(Cust record[],int count);
-
void CalculateTotal(Cust record[],int count);
-
void DisplayInvoice(Cust record[], int count);
-
void PressKey();
-
void GetYesNo(char &yesno);
-
void Error (char msg[]);
-
-
-
-
-
void main()
-
{
-
setupio();
-
-
// write your code here
-
-
struct Cust record[SIZE];
-
int count =0;
-
int option =0;
-
do
-
{
-
StartMenu(option);
-
switch(option)
-
{
-
case 1:
-
EnterDetails(record,count);
-
break;
-
case 2:
-
DisplayDetails(record,count);
-
break;
-
case 3:
-
DisplayTown(record,count);
-
break;
-
case 4:
-
CalculateAverage(record,count);
-
break;
-
case 5:
-
CalculateTotal(record, count);
-
break;
-
case 6:
-
DisplayInvoice(record,count);
-
break;
-
case 7:
-
cout << "Finished\n";
-
break;
-
-
default:
-
cout <<"Invalid Option";
-
}
-
} while (option !=7);
-
-
-
}
-
-
void EnterDetails (Cust record[], int &count)
-
{
-
clrscr();
-
char yesno;
-
GetYesNo (yesno);
-
-
while (yesno != 'N' && count < SIZE)
-
{
-
EnterCust (record [count]);
-
count++;
-
GetYesNo(yesno);
-
}
-
PressKey();
-
}
-
-
//Enter Customer Details
-
-
void EnterCust (Cust &record)
-
{
-
clrscr();
-
cout << "Cust No : ";
-
Input (record.custno);
-
-
while ( record.custno < 1 || record.custno >500 )
-
{
-
cout << "Invalid Customer Number\n";
-
gotoxy (20,4);
-
cout << "Cust No : ";
-
Input (record.custno);
-
}
-
-
gotoxy (20,6);
-
cout << "First Name : ";
-
Input (record.fname,15);
-
gotoxy (20,8);
-
cout << "Surname : ";
-
Input (record.surname,15);
-
gotoxy (20,10);
-
cout << "Street : ";
-
Input (record.street,25);
-
gotoxy (20,12);
-
cout << "Town : ";
-
Input (record.town,15);
-
gotoxy (20,14);
-
cout << "PostCode :";
-
Input (record.postcode,8);
-
gotoxy (20,16);
-
cout << "Phone Area Code :";
-
Input (record.areacode,5);
-
gotoxy (20,18);
-
cout << "Phone Number :";
-
Input (record.phoneno,6);
-
gotoxy (20,20);
-
cout << "Number of people :";
-
Input (record.noofpeople);
-
while ( record.noofpeople < 1 || record.noofpeople >8 )
-
{
-
cout << "The number of people is Invalid/n";
-
cout << "Number of people : ";
-
Input (record.noofpeople);
-
}
-
gotoxy (20,22);
-
cout << "Rental Type :";
-
Input (record.rentaltype);
-
}
-
-
//Calculate Hire Cost
-
-
void CalcRentalCost (Cust record)
-
-
{
-
-
if (record.rentaltype =='v'||record.rentaltype=='V')
-
{
-
record.rentalcost = (float)10.00;
-
}
-
-
if (record.rentaltype =='m'||record.rentaltype=='M')
-
{
-
record.rentalcost = (float)15.00;
-
}
-
-
if (record.rentaltype =='c'||record.rentaltype=='C')
-
{
-
record.rentalcost = (float)25.00;
-
}
-
-
}
-
-
// Calculate Total Cost
-
-
void CalculateTotal(Cust record[],int count)
-
{
-
int sub =0;
-
float total =0;
-
while (sub < count)
-
{
-
total = total +(record[sub].total);
-
sub++;
-
}
-
-
cout << "Total is: " << total;
-
}
-
-
// Calculate Average
-
-
void CalculateAverage(Cust record[],int count)
-
-
{ int sub=0;
-
float average =0;
-
float total;
-
while (sub < count)
-
{
-
average = total/sub;
-
sub++;
-
}
-
-
cout << "Average is: " <<average;
-
-
}
-
-
void DisplayDetails (Cust record[],int count)
-
{
-
char rentalt[16];
-
-
if (record.rent == 'v')
-
strcpy (rentalt, "Caravan");
-
-
if (record.rent == 'm')
-
strcpy (rentalt, "Mobile Home");
-
-
if (record.rent == 'c')
-
strcpy (rentalt, "Chalet");[/u]
-
cout << "Rental Type is: " << rentalt <<endl;
-
-
-
int sub=0;
-
while (sub < count)
-
{
-
DisplayCustomer (record[sub] );
-
sub++;
-
}
-
-
-
}
-
-
void DisplayCustomer(Cust record)
-
-
{
-
clrscr();
-
-
cout << "Customer Number :" << record.custno;
-
cout << endl;
-
cout << "Name : " << " " << record.fname << " " << record.surname <<endl;
-
cout << "Street :" << record.street <<endl;
-
cout << "Town :" <<record.town << endl;
-
cout << "Post code :" << record.postcode <<endl;
-
cout << "Phone Number :" << record.areacode <<" " << record.phoneno <<endl;
-
cout << "Rental Type :" <<record.rentaltype << endl;
-
cout << "Number of people :" <<record.noofpeople <<endl;
-
cout << "Electrical Charge :" <<record.electricalcost << endl;
-
PressKey();
-
-
}
-
void PressKey()
-
{
-
gotoxy(1,24);
-
cout << "Press Return Key To Continue";
-
getchar();
-
}
-
-
void GetYesNo (char &yesno)
-
{
-
cout << "Add a new customer (Y/N):";
-
Input (yesno);
-
yesno = toupper (yesno);
-
-
}
-
void Error (char msg[])
-
{
-
gotoxy (1,23);
-
cout << msg;
-
gotoxy (1,24);
-
PressKey();
-
gotoxy (1,24);
-
clreol();
-
gotoxy(1,23);
-
clreol();
-
}
-
-
void DisplayTown(Cust record[], int count)
-
{
-
clrscr();
-
char twn[16];
-
int result =0;
-
int sub =0;
-
bool custfound = false;
-
-
cout << "Please Enter Town :";
-
Input (twn,15);
-
-
while (sub < count)
-
{
-
result = (_strnicmp(twn,record[sub].town, strlen(twn)));
-
-
if (result ==0)
-
{
-
DisplayCustomer(record[sub]);
-
custfound = true;
-
}
-
sub++;
-
}
-
if (custfound ==false)
-
{
-
Error ("Town Not Found");
-
PressKey();
-
}
-
-
-
}
| |
Share:
Expert 512MB |
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have class/struct/union type.The problem area is underlined. Any help will be greatly appreciated. - #include <c:\cpp\input.h>
-
#include < time.h>
-
-
#define SIZE 20
-
-
struct Cust{
-
int custno;
-
char fname[16];
-
char surname[16];
-
char street[26];
-
char town[16];
-
char postcode[9];
-
char areacode[5];
-
char phoneno[6];
-
char rentaltype;
-
int noofpeople;
-
float rentalcost;
-
float electricalcost;
-
float total;
-
char rent;
-
-
};
-
-
-
void StartMenu(int &option);
-
void DisplayMenu1();
-
void DisplayTown(Cust record[],int count);
-
void EnterDetails(Cust record[], int &count);
-
void EnterCust(Cust &record);
-
void CalcRentalCost (Cust &record);
-
void DisplayDetails(Cust record[],int count);
-
void DisplayCustomer(Cust record);
-
void CalculateAverage(Cust record[],int count);
-
void CalculateTotal(Cust record[],int count);
-
void DisplayInvoice(Cust record[], int count);
-
void PressKey();
-
void GetYesNo(char &yesno);
-
void Error (char msg[]);
-
-
-
-
-
void main()
-
{
-
setupio();
-
-
// write your code here
-
-
struct Cust record[SIZE];
-
int count =0;
-
int option =0;
-
do
-
{
-
StartMenu(option);
-
switch(option)
-
{
-
case 1:
-
EnterDetails(record,count);
-
break;
-
case 2:
-
DisplayDetails(record,count);
-
break;
-
case 3:
-
DisplayTown(record,count);
-
break;
-
case 4:
-
CalculateAverage(record,count);
-
break;
-
case 5:
-
CalculateTotal(record, count);
-
break;
-
case 6:
-
DisplayInvoice(record,count);
-
break;
-
case 7:
-
cout << "Finished\n";
-
break;
-
-
default:
-
cout <<"Invalid Option";
-
}
-
} while (option !=7);
-
-
-
}
-
-
void EnterDetails (Cust record[], int &count)
-
{
-
clrscr();
-
char yesno;
-
GetYesNo (yesno);
-
-
while (yesno != 'N' && count < SIZE)
-
{
-
EnterCust (record [count]);
-
count++;
-
GetYesNo(yesno);
-
}
-
PressKey();
-
}
-
-
//Enter Customer Details
-
-
void EnterCust (Cust &record)
-
{
-
clrscr();
-
cout << "Cust No : ";
-
Input (record.custno);
-
-
while ( record.custno < 1 || record.custno >500 )
-
{
-
cout << "Invalid Customer Number\n";
-
gotoxy (20,4);
-
cout << "Cust No : ";
-
Input (record.custno);
-
}
-
-
gotoxy (20,6);
-
cout << "First Name : ";
-
Input (record.fname,15);
-
gotoxy (20,8);
-
cout << "Surname : ";
-
Input (record.surname,15);
-
gotoxy (20,10);
-
cout << "Street : ";
-
Input (record.street,25);
-
gotoxy (20,12);
-
cout << "Town : ";
-
Input (record.town,15);
-
gotoxy (20,14);
-
cout << "PostCode :";
-
Input (record.postcode,8);
-
gotoxy (20,16);
-
cout << "Phone Area Code :";
-
Input (record.areacode,5);
-
gotoxy (20,18);
-
cout << "Phone Number :";
-
Input (record.phoneno,6);
-
gotoxy (20,20);
-
cout << "Number of people :";
-
Input (record.noofpeople);
-
while ( record.noofpeople < 1 || record.noofpeople >8 )
-
{
-
cout << "The number of people is Invalid/n";
-
cout << "Number of people : ";
-
Input (record.noofpeople);
-
}
-
gotoxy (20,22);
-
cout << "Rental Type :";
-
Input (record.rentaltype);
-
}
-
-
//Calculate Hire Cost
-
-
void CalcRentalCost (Cust record)
-
-
{
-
-
if (record.rentaltype =='v'||record.rentaltype=='V')
-
{
-
record.rentalcost = (float)10.00;
-
}
-
-
if (record.rentaltype =='m'||record.rentaltype=='M')
-
{
-
record.rentalcost = (float)15.00;
-
}
-
-
if (record.rentaltype =='c'||record.rentaltype=='C')
-
{
-
record.rentalcost = (float)25.00;
-
}
-
-
}
-
-
// Calculate Total Cost
-
-
void CalculateTotal(Cust record[],int count)
-
{
-
int sub =0;
-
float total =0;
-
while (sub < count)
-
{
-
total = total +(record[sub].total);
-
sub++;
-
}
-
-
cout << "Total is: " << total;
-
}
-
-
// Calculate Average
-
-
void CalculateAverage(Cust record[],int count)
-
-
{ int sub=0;
-
float average =0;
-
float total;
-
while (sub < count)
-
{
-
average = total/sub;
-
sub++;
-
}
-
-
cout << "Average is: " <<average;
-
-
}
-
-
void DisplayDetails (Cust record[],int count)
-
{
-
char rentalt[16];
-
-
if (record.rent == 'v')
-
strcpy (rentalt, "Caravan");
-
-
if (record.rent == 'm')
-
strcpy (rentalt, "Mobile Home");
-
-
if (record.rent == 'c')
-
strcpy (rentalt, "Chalet");[/u]
-
cout << "Rental Type is: " << rentalt <<endl;
-
-
-
int sub=0;
-
while (sub < count)
-
{
-
DisplayCustomer (record[sub] );
-
sub++;
-
}
-
-
-
}
-
-
void DisplayCustomer(Cust record)
-
-
{
-
clrscr();
-
-
cout << "Customer Number :" << record.custno;
-
cout << endl;
-
cout << "Name : " << " " << record.fname << " " << record.surname <<endl;
-
cout << "Street :" << record.street <<endl;
-
cout << "Town :" <<record.town << endl;
-
cout << "Post code :" << record.postcode <<endl;
-
cout << "Phone Number :" << record.areacode <<" " << record.phoneno <<endl;
-
cout << "Rental Type :" <<record.rentaltype << endl;
-
cout << "Number of people :" <<record.noofpeople <<endl;
-
cout << "Electrical Charge :" <<record.electricalcost << endl;
-
PressKey();
-
-
}
-
void PressKey()
-
{
-
gotoxy(1,24);
-
cout << "Press Return Key To Continue";
-
getchar();
-
}
-
-
void GetYesNo (char &yesno)
-
{
-
cout << "Add a new customer (Y/N):";
-
Input (yesno);
-
yesno = toupper (yesno);
-
-
}
-
void Error (char msg[])
-
{
-
gotoxy (1,23);
-
cout << msg;
-
gotoxy (1,24);
-
PressKey();
-
gotoxy (1,24);
-
clreol();
-
gotoxy(1,23);
-
clreol();
-
}
-
-
void DisplayTown(Cust record[], int count)
-
{
-
clrscr();
-
char twn[16];
-
int result =0;
-
int sub =0;
-
bool custfound = false;
-
-
cout << "Please Enter Town :";
-
Input (twn,15);
-
-
while (sub < count)
-
{
-
result = (_strnicmp(twn,record[sub].town, strlen(twn)));
-
-
if (result ==0)
-
{
-
DisplayCustomer(record[sub]);
-
custfound = true;
-
}
-
sub++;
-
}
-
if (custfound ==false)
-
{
-
Error ("Town Not Found");
-
PressKey();
-
}
-
-
-
}
In your DisplayDetails() function, you take an array of "Custs" as an arguement: -
void DisplayDetails(Cust record[],int count);
-
but then you have record.rent. I don't think you can do that since record is an array. Try indexing it like you did with the others:
or remove your brackets from the arguement being taken.
Also, try to post only the code that is relevant to your problem.
| | Expert Mod 8TB |
In your DisplayDetails() function, you take an array of "Custs" as an arguement: -
void DisplayDetails(Cust record[],int count);
-
Strictly speaking that syntax in a function declaration/definition indicates a pointer not an array. Normally it would be used (it at all) if the pointer was in fact a pointer to the first element of any array (i.e. a pointer to an array by convention rather than by language rules) but it is functionally equivalent to (and interchangeable with) -
void DisplayDetails(Cust *record,int count);
-
| | Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
reply
views
Thread by Cary |
last post: by
|
7 posts
views
Thread by inkexit |
last post: by
|
7 posts
views
Thread by GRoll35 |
last post: by
|
1 post
views
Thread by uday |
last post: by
| | |
6 posts
views
Thread by hsmit.home |
last post: by
| | | | | | | | | | | | |