Struct Problem

Hi, i am creating a struct program and then suddenly errors came and don't know why. There are red wavy lines under the .customer.name.etc and so on. Please help! Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  #include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
struct Customer{

	struct{
		char firstName[20];
		char lastName[20];
	}name;

	int contactNo;

	struct{

		struct{
			int code;
			char name[40];
			double price;
		}item;

		struct{
			int day;
			int month;
			int year;
		}date;

		int quantity;

	}order;
}

int main()
{
	cout<<"Enter 3 customers.";
		for (int i=0;i<3;i++){
	cout<<"\n\CUSTOMER INFORMATION "<<(i+1);
	cout<<"First Name: ";
	cin.getline(Customer.name.firstName, 20);
	cout<<"Last Name: ";
	cin.getline(Customer.name.lastName, 20);
	cout<<"Contact No: ";
	cin>>Customer.contactNo;
	cout<<"Order Date: ";
	cout<<"Day: ";
	cin>>Customer.order.date.day;
	cout<<"Month: ";
	cin>>Customer.order.date.month;
	cout<<"Year: ";
	cin>>Customer.order.date.year;
		for (int i=0;i<3;i++){
	cout<<"Enter"<<i+1<<" items";
	cout<<"ID: ";
	cin>>Customer.order.item.code;
	cout<<"Name: ";
	cin.getline(Customer.order.item.name, 20);
	cout<<"Price: ";
	cin>>Customer.order.item.price;
							}
						}


}
listen to your compiler. it's telling you what's up.


1>c:\users\desktop\scrap\temp\temp\main.cpp(33): error C2628: 'Customer' followed by 'int' is illegal (did you forget a ';'?)
1>c:\users\desktop\scrap\temp\temp\main.cpp(34): error C3874: return type of 'main' should be 'int' instead of 'Customer'
1>c:\users\desktop\scrap\temp\temp\main.cpp(37): warning C4129: 'C' : unrecognized character escape sequence
1>c:\users\desktop\scrap\temp\temp\main.cpp(39): warning C4832: token '.' is illegal after UDT 'Customer'
1>          c:\users\desktop\scrap\temp\temp\main.cpp(5) : see declaration of 'Customer'

etc etc
Uhmm, thanks about that but i dont really understand whats through it lol. Can you please help me and point out what to change? Thanksss, please guide me.
(did you forget a ';'?)

means add a semi-colon at the end of line 31.

 'C' : unrecognized character escape sequence

means \C is illegal on line 37. Perhaps you meant

cout<<"\n\nCUSTOMER INFORMATION "<<(i+1);

stuff like that.

edit: it's not a problem with the struct as your thread title suggests, it's a problem with basic syntax.
Last edited on
Thankss! But, it still has a problem and it still wont run. it got an error somewhere ....date.etc... and ....name.etc... please guide me here too! Thank you so much!. what is wrong with my code?:)
Topic archived. No new replies allowed.