473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error C2228: left of '.rent' must have class/struct/union type

1
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.

Expand|Select|Wrap|Line Numbers
  1. #include <c:\cpp\input.h>
  2. #include < time.h>
  3.  
  4. #define SIZE 20
  5.  
  6. struct Cust{
  7.         int custno;
  8.         char fname[16];
  9.         char surname[16];
  10.         char street[26];
  11.         char town[16];
  12.         char postcode[9];
  13.         char areacode[5];
  14.         char phoneno[6];
  15.         char rentaltype;
  16.         int noofpeople;
  17.         float rentalcost;
  18.         float electricalcost;
  19.         float total;
  20.         char rent;
  21.  
  22. };
  23.  
  24.  
  25. void StartMenu(int &option);
  26. void DisplayMenu1();
  27. void DisplayTown(Cust record[],int count);
  28. void EnterDetails(Cust record[], int &count);
  29. void EnterCust(Cust &record);
  30. void CalcRentalCost (Cust &record);
  31. void DisplayDetails(Cust record[],int count);
  32. void DisplayCustomer(Cust record);
  33. void CalculateAverage(Cust record[],int count);
  34. void CalculateTotal(Cust record[],int count);
  35. void DisplayInvoice(Cust record[], int count);
  36. void PressKey();
  37. void GetYesNo(char &yesno);
  38. void Error (char msg[]);
  39.  
  40.  
  41.  
  42.  
  43. void main()
  44. {
  45. setupio();
  46.  
  47. // write your code here
  48.  
  49. struct Cust record[SIZE];
  50. int count =0;
  51. int option =0;
  52. do
  53. {
  54.     StartMenu(option);
  55.     switch(option)
  56.     {
  57.     case 1:
  58.     EnterDetails(record,count);
  59.     break;
  60.     case 2:
  61.     DisplayDetails(record,count);
  62.     break;
  63.     case 3:
  64.     DisplayTown(record,count);
  65.     break;
  66.     case 4:
  67.     CalculateAverage(record,count);
  68.     break;
  69.     case 5:
  70.     CalculateTotal(record, count);
  71.     break;
  72.     case 6:
  73.     DisplayInvoice(record,count);
  74.     break;
  75.     case 7:
  76.     cout << "Finished\n";
  77.     break;
  78.  
  79.     default:
  80.     cout <<"Invalid Option";
  81.     }
  82.     } while (option !=7);
  83.  
  84.  
  85. }
  86.  
  87. void EnterDetails (Cust record[], int &count)
  88. {
  89.     clrscr();
  90.     char yesno;
  91.     GetYesNo (yesno);
  92.  
  93.     while (yesno != 'N' && count < SIZE)
  94.     {
  95.         EnterCust (record [count]);
  96.         count++;
  97.         GetYesNo(yesno);
  98.     }
  99.         PressKey();
  100. }
  101.  
  102. //Enter Customer Details
  103.  
  104. void EnterCust (Cust &record)
  105. {
  106.     clrscr();
  107.     cout << "Cust No : ";
  108.     Input (record.custno);
  109.  
  110.     while ( record.custno < 1 || record.custno >500 )
  111.     {
  112.         cout << "Invalid Customer Number\n";
  113.         gotoxy (20,4);
  114.         cout << "Cust No : ";
  115.         Input (record.custno);
  116.     }
  117.  
  118.         gotoxy (20,6);
  119.         cout << "First Name : ";
  120.         Input (record.fname,15);
  121.         gotoxy (20,8);
  122.         cout << "Surname : ";
  123.         Input (record.surname,15);
  124.         gotoxy (20,10);
  125.         cout << "Street : ";
  126.         Input (record.street,25);
  127.         gotoxy (20,12);
  128.         cout << "Town : ";
  129.         Input (record.town,15);
  130.         gotoxy (20,14);
  131.         cout << "PostCode :";
  132.         Input (record.postcode,8);
  133.         gotoxy (20,16);
  134.         cout << "Phone Area Code :";
  135.         Input (record.areacode,5);
  136.         gotoxy (20,18);
  137.         cout << "Phone Number :";
  138.         Input (record.phoneno,6);
  139.         gotoxy (20,20);
  140.         cout << "Number of people :";
  141.         Input (record.noofpeople);
  142.     while ( record.noofpeople < 1 || record.noofpeople >8 )
  143.     {
  144.         cout << "The number of people is Invalid/n";
  145.         cout << "Number of people : ";
  146.         Input (record.noofpeople);
  147.     }    
  148.         gotoxy (20,22);
  149.         cout << "Rental Type :";
  150.         Input (record.rentaltype);
  151.     }
  152.  
  153. //Calculate Hire Cost
  154.  
  155. void CalcRentalCost (Cust record)
  156.  
  157.     {
  158.  
  159.     if (record.rentaltype =='v'||record.rentaltype=='V')
  160.         {
  161.             record.rentalcost = (float)10.00;
  162.     }
  163.  
  164.     if (record.rentaltype =='m'||record.rentaltype=='M')
  165.         {
  166.             record.rentalcost = (float)15.00;
  167.     }        
  168.  
  169.     if (record.rentaltype =='c'||record.rentaltype=='C')
  170.         {
  171.             record.rentalcost = (float)25.00;
  172.     }
  173.  
  174. }
  175.  
  176. // Calculate Total Cost
  177.  
  178. void CalculateTotal(Cust record[],int count)
  179. {
  180.     int sub =0;
  181.     float total =0;
  182.     while (sub < count)
  183.     {
  184.          total = total +(record[sub].total);
  185.         sub++;
  186.     }
  187.  
  188.     cout << "Total is: " << total;
  189. }
  190.  
  191. // Calculate Average
  192.  
  193. void CalculateAverage(Cust record[],int count)
  194.  
  195. {    int sub=0;
  196.     float average =0;
  197.     float total;
  198.     while (sub < count)
  199.     {
  200.         average = total/sub;
  201.         sub++;
  202.     }
  203.  
  204.     cout << "Average is: " <<average;
  205.  
  206. }
  207.  
  208. void DisplayDetails (Cust record[],int count)
  209. {
  210.     char rentalt[16];
  211.  
  212.     if (record.rent == 'v')
  213.         strcpy (rentalt, "Caravan");
  214.  
  215.     if (record.rent == 'm')
  216.         strcpy (rentalt, "Mobile Home");
  217.  
  218.     if (record.rent == 'c')
  219.         strcpy (rentalt, "Chalet");[/u]
  220.     cout << "Rental Type is: " << rentalt <<endl;
  221.  
  222.  
  223.     int sub=0;
  224.     while (sub < count)
  225.     {
  226.         DisplayCustomer (record[sub] );
  227.         sub++;
  228.     }
  229.  
  230.  
  231. }
  232.  
  233. void DisplayCustomer(Cust record)
  234.  
  235. {
  236.     clrscr();
  237.  
  238.     cout << "Customer Number :" << record.custno;
  239.     cout << endl;
  240.     cout << "Name : " << " " << record.fname << " " << record.surname <<endl;
  241.     cout << "Street :" << record.street <<endl;
  242.     cout << "Town :" <<record.town << endl;
  243.     cout << "Post code :" << record.postcode <<endl;
  244.     cout << "Phone Number :" << record.areacode <<" " << record.phoneno <<endl;
  245.     cout << "Rental Type :" <<record.rentaltype << endl;
  246.     cout << "Number of people :" <<record.noofpeople <<endl;
  247.     cout << "Electrical Charge :" <<record.electricalcost << endl;
  248.     PressKey();
  249.  
  250. }
  251. void PressKey()
  252. {
  253.     gotoxy(1,24);
  254.     cout << "Press Return Key To Continue";
  255.     getchar();
  256. }
  257.  
  258. void GetYesNo (char &yesno)
  259. {
  260.     cout << "Add a new customer (Y/N):";
  261.     Input (yesno);
  262.     yesno = toupper (yesno);
  263.  
  264. }
  265. void Error (char msg[])
  266. {
  267.     gotoxy (1,23);
  268.     cout << msg;
  269.     gotoxy (1,24);
  270.     PressKey();
  271.     gotoxy (1,24);
  272.     clreol();
  273.     gotoxy(1,23);
  274.     clreol();
  275. }
  276.  
  277. void DisplayTown(Cust record[], int count)
  278. {
  279.     clrscr();
  280.     char twn[16];
  281.     int result =0;
  282.     int sub =0;
  283.     bool custfound = false;
  284.  
  285.     cout << "Please Enter Town :";
  286.     Input (twn,15);
  287.  
  288.     while (sub < count)
  289.     {
  290.         result = (_strnicmp(twn,record[sub].town, strlen(twn)));
  291.  
  292.         if (result ==0)
  293.         {
  294.             DisplayCustomer(record[sub]);
  295.             custfound = true;
  296.         }
  297.         sub++;
  298.     }
  299.     if (custfound ==false)
  300.     {
  301.         Error ("Town Not Found");
  302.         PressKey();
  303.     }
  304.  
  305.  
  306. }
May 7 '07 #1
2 16099
ilikepython
844 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.

Expand|Select|Wrap|Line Numbers
  1. #include <c:\cpp\input.h>
  2. #include < time.h>
  3.  
  4. #define SIZE 20
  5.  
  6. struct Cust{
  7.         int custno;
  8.         char fname[16];
  9.         char surname[16];
  10.         char street[26];
  11.         char town[16];
  12.         char postcode[9];
  13.         char areacode[5];
  14.         char phoneno[6];
  15.         char rentaltype;
  16.         int noofpeople;
  17.         float rentalcost;
  18.         float electricalcost;
  19.         float total;
  20.         char rent;
  21.  
  22. };
  23.  
  24.  
  25. void StartMenu(int &option);
  26. void DisplayMenu1();
  27. void DisplayTown(Cust record[],int count);
  28. void EnterDetails(Cust record[], int &count);
  29. void EnterCust(Cust &record);
  30. void CalcRentalCost (Cust &record);
  31. void DisplayDetails(Cust record[],int count);
  32. void DisplayCustomer(Cust record);
  33. void CalculateAverage(Cust record[],int count);
  34. void CalculateTotal(Cust record[],int count);
  35. void DisplayInvoice(Cust record[], int count);
  36. void PressKey();
  37. void GetYesNo(char &yesno);
  38. void Error (char msg[]);
  39.  
  40.  
  41.  
  42.  
  43. void main()
  44. {
  45. setupio();
  46.  
  47. // write your code here
  48.  
  49. struct Cust record[SIZE];
  50. int count =0;
  51. int option =0;
  52. do
  53. {
  54.     StartMenu(option);
  55.     switch(option)
  56.     {
  57.     case 1:
  58.     EnterDetails(record,count);
  59.     break;
  60.     case 2:
  61.     DisplayDetails(record,count);
  62.     break;
  63.     case 3:
  64.     DisplayTown(record,count);
  65.     break;
  66.     case 4:
  67.     CalculateAverage(record,count);
  68.     break;
  69.     case 5:
  70.     CalculateTotal(record, count);
  71.     break;
  72.     case 6:
  73.     DisplayInvoice(record,count);
  74.     break;
  75.     case 7:
  76.     cout << "Finished\n";
  77.     break;
  78.  
  79.     default:
  80.     cout <<"Invalid Option";
  81.     }
  82.     } while (option !=7);
  83.  
  84.  
  85. }
  86.  
  87. void EnterDetails (Cust record[], int &count)
  88. {
  89.     clrscr();
  90.     char yesno;
  91.     GetYesNo (yesno);
  92.  
  93.     while (yesno != 'N' && count < SIZE)
  94.     {
  95.         EnterCust (record [count]);
  96.         count++;
  97.         GetYesNo(yesno);
  98.     }
  99.         PressKey();
  100. }
  101.  
  102. //Enter Customer Details
  103.  
  104. void EnterCust (Cust &record)
  105. {
  106.     clrscr();
  107.     cout << "Cust No : ";
  108.     Input (record.custno);
  109.  
  110.     while ( record.custno < 1 || record.custno >500 )
  111.     {
  112.         cout << "Invalid Customer Number\n";
  113.         gotoxy (20,4);
  114.         cout << "Cust No : ";
  115.         Input (record.custno);
  116.     }
  117.  
  118.         gotoxy (20,6);
  119.         cout << "First Name : ";
  120.         Input (record.fname,15);
  121.         gotoxy (20,8);
  122.         cout << "Surname : ";
  123.         Input (record.surname,15);
  124.         gotoxy (20,10);
  125.         cout << "Street : ";
  126.         Input (record.street,25);
  127.         gotoxy (20,12);
  128.         cout << "Town : ";
  129.         Input (record.town,15);
  130.         gotoxy (20,14);
  131.         cout << "PostCode :";
  132.         Input (record.postcode,8);
  133.         gotoxy (20,16);
  134.         cout << "Phone Area Code :";
  135.         Input (record.areacode,5);
  136.         gotoxy (20,18);
  137.         cout << "Phone Number :";
  138.         Input (record.phoneno,6);
  139.         gotoxy (20,20);
  140.         cout << "Number of people :";
  141.         Input (record.noofpeople);
  142.     while ( record.noofpeople < 1 || record.noofpeople >8 )
  143.     {
  144.         cout << "The number of people is Invalid/n";
  145.         cout << "Number of people : ";
  146.         Input (record.noofpeople);
  147.     }    
  148.         gotoxy (20,22);
  149.         cout << "Rental Type :";
  150.         Input (record.rentaltype);
  151.     }
  152.  
  153. //Calculate Hire Cost
  154.  
  155. void CalcRentalCost (Cust record)
  156.  
  157.     {
  158.  
  159.     if (record.rentaltype =='v'||record.rentaltype=='V')
  160.         {
  161.             record.rentalcost = (float)10.00;
  162.     }
  163.  
  164.     if (record.rentaltype =='m'||record.rentaltype=='M')
  165.         {
  166.             record.rentalcost = (float)15.00;
  167.     }        
  168.  
  169.     if (record.rentaltype =='c'||record.rentaltype=='C')
  170.         {
  171.             record.rentalcost = (float)25.00;
  172.     }
  173.  
  174. }
  175.  
  176. // Calculate Total Cost
  177.  
  178. void CalculateTotal(Cust record[],int count)
  179. {
  180.     int sub =0;
  181.     float total =0;
  182.     while (sub < count)
  183.     {
  184.          total = total +(record[sub].total);
  185.         sub++;
  186.     }
  187.  
  188.     cout << "Total is: " << total;
  189. }
  190.  
  191. // Calculate Average
  192.  
  193. void CalculateAverage(Cust record[],int count)
  194.  
  195. {    int sub=0;
  196.     float average =0;
  197.     float total;
  198.     while (sub < count)
  199.     {
  200.         average = total/sub;
  201.         sub++;
  202.     }
  203.  
  204.     cout << "Average is: " <<average;
  205.  
  206. }
  207.  
  208. void DisplayDetails (Cust record[],int count)
  209. {
  210.     char rentalt[16];
  211.  
  212.     if (record.rent == 'v')
  213.         strcpy (rentalt, "Caravan");
  214.  
  215.     if (record.rent == 'm')
  216.         strcpy (rentalt, "Mobile Home");
  217.  
  218.     if (record.rent == 'c')
  219.         strcpy (rentalt, "Chalet");[/u]
  220.     cout << "Rental Type is: " << rentalt <<endl;
  221.  
  222.  
  223.     int sub=0;
  224.     while (sub < count)
  225.     {
  226.         DisplayCustomer (record[sub] );
  227.         sub++;
  228.     }
  229.  
  230.  
  231. }
  232.  
  233. void DisplayCustomer(Cust record)
  234.  
  235. {
  236.     clrscr();
  237.  
  238.     cout << "Customer Number :" << record.custno;
  239.     cout << endl;
  240.     cout << "Name : " << " " << record.fname << " " << record.surname <<endl;
  241.     cout << "Street :" << record.street <<endl;
  242.     cout << "Town :" <<record.town << endl;
  243.     cout << "Post code :" << record.postcode <<endl;
  244.     cout << "Phone Number :" << record.areacode <<" " << record.phoneno <<endl;
  245.     cout << "Rental Type :" <<record.rentaltype << endl;
  246.     cout << "Number of people :" <<record.noofpeople <<endl;
  247.     cout << "Electrical Charge :" <<record.electricalcost << endl;
  248.     PressKey();
  249.  
  250. }
  251. void PressKey()
  252. {
  253.     gotoxy(1,24);
  254.     cout << "Press Return Key To Continue";
  255.     getchar();
  256. }
  257.  
  258. void GetYesNo (char &yesno)
  259. {
  260.     cout << "Add a new customer (Y/N):";
  261.     Input (yesno);
  262.     yesno = toupper (yesno);
  263.  
  264. }
  265. void Error (char msg[])
  266. {
  267.     gotoxy (1,23);
  268.     cout << msg;
  269.     gotoxy (1,24);
  270.     PressKey();
  271.     gotoxy (1,24);
  272.     clreol();
  273.     gotoxy(1,23);
  274.     clreol();
  275. }
  276.  
  277. void DisplayTown(Cust record[], int count)
  278. {
  279.     clrscr();
  280.     char twn[16];
  281.     int result =0;
  282.     int sub =0;
  283.     bool custfound = false;
  284.  
  285.     cout << "Please Enter Town :";
  286.     Input (twn,15);
  287.  
  288.     while (sub < count)
  289.     {
  290.         result = (_strnicmp(twn,record[sub].town, strlen(twn)));
  291.  
  292.         if (result ==0)
  293.         {
  294.             DisplayCustomer(record[sub]);
  295.             custfound = true;
  296.         }
  297.         sub++;
  298.     }
  299.     if (custfound ==false)
  300.     {
  301.         Error ("Town Not Found");
  302.         PressKey();
  303.     }
  304.  
  305.  
  306. }
In your DisplayDetails() function, you take an array of "Custs" as an arguement:
Expand|Select|Wrap|Line Numbers
  1. void DisplayDetails(Cust record[],int count);
  2.  
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:
Expand|Select|Wrap|Line Numbers
  1. record[sub].rent
  2.  
or remove your brackets from the arguement being taken.

Also, try to post only the code that is relevant to your problem.
May 7 '07 #2
Banfa
9,065 Expert Mod 8TB
In your DisplayDetails() function, you take an array of "Custs" as an arguement:
Expand|Select|Wrap|Line Numbers
  1. void DisplayDetails(Cust record[],int count);
  2.  
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)

Expand|Select|Wrap|Line Numbers
  1. void DisplayDetails(Cust *record,int count);
  2.  
May 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Cary | last post by:
Trying to install on SuSE 8.2 from source. ../configure --with-apxs=/usr/local/apache/bin/apxs --with-mysql --with-unixODBC=/usr/lib getting this error: /root/php-4.3.2/ext/odbc/php_odbc.c -o...
7
by: inkexit | last post by:
I'm getting these two error mesages when I try to compile the below source code: error C2065: 'input_file' : undeclared identifier error C2228: left of '.eof' must have class/struct/union type ...
7
by: GRoll35 | last post by:
I have 3 files here - Header/Implementation/Driver All it has to do is send the user's input (age)..to the class and the class will figure out the price of the ticket. I'm suppose to create the...
1
by: uday | last post by:
Hi, I am new to visual c++ and I am trying to compile a Decoder project with library in it. I tried to create a win32 console application and tried to add a compiled static library to it. I...
3
by: aventerprise | last post by:
<html> <head> <title></title> <script type="javascript" src="E:\Internet\positive_gearing.js"> function positve_gearing() { var price = form.price.value; var rates = form.rates.value;
2
by: dblbac | last post by:
i have gone through my c++ program and i keep getting the same error messages: error C2065: 'indata' : undeclared identifier error C2228: left of '.open' must have class/struct/union my program...
6
by: hsmit.home | last post by:
Hello, I came across a strange error and it's really been bugging me. Maybe someone else has come across this and any insight would be appreciated. What I'm trying to accomplish is using...
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
3
by: rajatamilarasu | last post by:
for(i=0 ; i<listNum ; i++) { checker.checkN1DisagreementSwitch(pRep_Active_SList.ChassisID, pRep_Active_SList.SlotID, pRep_Standby_SList.ChassisID, pRep_Standby_SList.SlotID); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.