Structure

Check the desired output here(problem 3) ---> https://app.box.com/s/l4jompt825z0kcwk37vq

My output:
The image there is my problem --> http://i57.tinypic.com/3005kkm.png

//I don't know what to do and it's so difficult. :/

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<iostream>
#include<iomanip>
using namespace std;
double total_price[2];

struct customer{
	struct{
		char lastName[50];
		char firstName[50];
	}name;
	int contactNo;
	struct{
		int day;
		int month;
		int year;
		struct{
			int ID;
			char name[2];
			double price[2];
		}item;
		int quantity[2];
	}order;
};

void newLine();

int main()
{
	customer cust;
	cout << "Enter 3 customers: ";
	cout << "\n\n";
	for (int i = 0; i < 3; i++)
	{
		cout << "Customer Information " << i + 1 << "\n";
		cout << "First Name: ";
		cin.getline(cust.name.firstName, 49);
		cout << "Last Name: ";
		cin.getline(cust.name.firstName, 49);
		cout << "Contact No.: ";
		cin >> cust.contactNo;
		newLine();
		cout << "Order Date: \n";
		cout << "Day: ";
		cin >> cust.order.day;
		newLine();
		cout << "Month: ";
		cin >> cust.order.month;
		newLine();
		cout << "Year: ";
		cin >> cust.order.year;
		newLine();
		cout << "Enter 3 Items: \n";
		cout << "ID: ";
		cin >> cust.order.item.ID;
		newLine();
		cout << "Name: ";
		cin >> cust.order.item.name[0];
		newLine();
		cout << "Price: ";
		cin >> cust.order.item.price[0];
		newLine();
		cout << "Quantity: ";
		cin >> cust.order.quantity[0];
		newLine();
		cout << "ID: ";
		cin >> cust.order.item.ID;
		newLine();
		cout << "Name: ";
		cin >> cust.order.item.name[1];
		newLine();
		cout << "Price: ";
		cin >> cust.order.item.price[1];
		newLine();
		cout << "Quantity: ";
		cin >> cust.order.quantity[1];
		newLine();
		cout << "ID: ";
		cin >> cust.order.item.ID;
		newLine();
		cout << "Name: ";
		cin >> cust.order.item.name[2];
		newLine();
		cout << "Price: ";
		cin >> cust.order.item.price[2];
		newLine();
		cout << "Quantity: ";
		cin >> cust.order.quantity[2];
		newLine();
	}
	cout << "SUMMARY REPORT \n";
	cout << setw(10) << "#"
		<< setw(20) << "Customer Name"
		<< setw(16) << "Order Date"
		<< setw(10) << "Items"
		<< setw(10) << "Price"
		<< setw(10) << "Quantity";

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	for (int i = 0; i < 3; i++)
	{
		cout << endl
			<< setw(10) << i + 1
			<< setw(20) << cust.name.lastName << " , " << cust.name.firstName
			<< setw(16) << cust.order.month << "/" << cust.order.day << "/" << cust.order.year;
		cout << endl;
		cout << setw(56) << cust.order.item.name[i]
			<< setw(10) << setprecision(4) << cust.order.item.price[i]
			<< setw(10) << cust.order.quantity[i];
		cout << endl;
		cout << endl;
		for (int k = 0; k < 3; i++){
			total_price[k] = (cust.order.item.price[k] * cust.order.quantity[k]);
		}
		double TP = total_price[0] + total_price[1] + total_price[2];
		cout << setw(41) << setprecision(4) << "TOTAL PRICE: " << TP;
	}
	system("pause>0");
	return 0;
}

void newLine()
{
	char s; do{
		cin.get(s);
	} while (s != '\n');
}

//I think this is the particular code that i got wrong and needs fixing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
for (int i = 0; i < 3; i++)
	{
		cout << endl
			<< setw(10) << i + 1
			<< setw(20) << cust.name.lastName << " , " << cust.name.firstName
			<< setw(16) << cust.order.month << "/" << cust.order.day << "/" << cust.order.year;
		cout << endl;
		cout << setw(56) << cust.order.item.name[i]
			<< setw(10) << setprecision(4) << cust.order.item.price[i]
			<< setw(10) << cust.order.quantity[i];
		cout << endl;
		cout << endl;
		for (int k = 0; k < 3; i++){
			total_price[k] = (cust.order.item.price[k] * cust.order.quantity[k]);
		}
		double TP = total_price[0] + total_price[1] + total_price[2];
		cout << setw(41) << setprecision(4) << "TOTAL PRICE: " << TP;
	}
The problem is on line 38:

1
2
		cout << "Last Name: ";
		cin.getline(cust.name.firstName, 49);


lastName remains uninitialized
Done! But still have problems...
It only reads the 3rd entry
Last edited on
Fixed it!
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void newLine();

double total(double, double, double, int, int, int);

struct customer
{
	string contactNo;
	struct {
		string lastName;
		string firstName;
	}name;
	struct {
		struct {
			string day, month, year;
		}date;
		struct{
			string ID;
			string name;
			double price;
			int quantity;
		}item[3];

	}order;
};
int sum;

int main()
{
	customer cust[3];
	cout << "Enter 3 customers: " << "\n" << "\n";
	
	for (int i = 0; i < 3; i++)
	{
		cout << "CUSTOMER INFORMATION " << i + 1 << "\n";
		cout << "First Name: ";
		cin >> cust[i].name.firstName;
		newLine();
		cout << "Last Name: ";
		getline(cin, cust[i].name.lastName);
		cout << "Contact No: ";
		cin >> cust[i].contactNo;
		cout << "Order Date:\n";
		cout << "Day: ";
		cin >> cust[i].order.date.day;
		cout << "Month: ";
		cin >> cust[i].order.date.month;
		cout << "Year: ";
		cin >> cust[i].order.date.year;
		cout << "Enter 3 items: " << "\n";
		
		for (int j = 0; j < 3; j++)
		{
			cout << "ID: ";
			cin >> cust[i].order.item[j].ID;
			cout << "Name: ";
			cin >> cust[i].order.item[j].name;
			cout << "Price: ";
			cin >> cust[i].order.item[j].price;
			cout << "Quantity: ";
			cin >> cust[i].order.item[j].quantity;
		}
		system("cls");
	}
	cout << "SUMMARY REPORT\n";
	cout << setw(5) << "#" 
		<< setw(20) << "Customer Name " 
		<< setw(20) << "Order Date " 
		<< setw(10) << "Items" 
		<< setw(10) << "Price" 
		<< setw(16) << "Quantity\n";
	
	for (int i = 0; i < 3; i++)
	{
		cout << setw(5) << i + 1 
			<< setw(15) << cust[i].name.lastName << ", " << cust[i].name.firstName 
			<< setw(15) << cust[i].order.date.month << "/" << cust[i].order.date.day << "/" << cust[i].order.date.year << "\n";
		
		for (int j = 0; j < 3; j++)
		{
			cout << setw(55) << cust[i].order.item[j].name 
				<< setw(10) << cust[i].order.item[j].price 
				<< setw(10) << cust[i].order.item[j].quantity;
			cout << "\n";
		}
		
		cout.setf(ios::fixed);
		cout.precision(2);

		cout << setw(70) << "TOTAL PRICE: " << total(cust[i].order.item[0].price, cust[i].order.item[1].price, cust[i].order.item[2].price,
			cust[i].order.item[0].quantity, cust[i].order.item[1].quantity, cust[i].order.item[2].quantity) << "\n";
	}
	system("pause>0");
	return 0;
}

double total(double p1, double p2, double p3, int q1, int q2, int q3)
{
	double sum = ((p1*q1) + (p2*q2) + (p3*q3));
	return sum;
}

void newLine()
{
	char s; do{ 
		cin.get(s); 
	} while (s != '\n');
}

Topic archived. No new replies allowed.