Positioning Problem

Hi, i am creating a struct program. i have my code with me but the only problem is the date and name won't show up and won't position itself properly. I don;t know where the problem is, please point it out and guide me 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
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
 // Struct Prac_1.cpp : Defines the entry point for the console application.
//

#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[20];
			double price;
		}item;

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

		int quantity;

	}order;
};

void newline();

int main()
{
	Customer yourCust[1];
	int i;
	cout<<"Enter 1 customers.";
		for (i=0; i<1; i++)
	{
		cout<<"\n\nCUSTOMER INFORMATION "<<(i+1);
		cout<<"\nFirst Name: ";
		cin.getline(yourCust[i].name.firstName, 19);
		cout<<"\nLast Name: ";
		cin.getline(yourCust[i].name.lastName, 19);
		cout<<"\nContact No: ";
		cin>>yourCust[i].contactNo;
		cout<<"\n\nOrder Date.";
		cout<<"\nDay: ";
		cin>>yourCust[i].order.date.day;
		cout<<"\nMonth: ";
		cin>>yourCust[i].order.date.month;
		cout<<"\nYear: ";
		cin>>yourCust[i].order.date.year;
		for (int j=0;j<1;j++)
		{
			cout<<"Enter 1  items.";
			cout<<"\n"<<j+1<<" ITEM";
			cout<<"\nID: ";
			cin>>yourCust[j].order.item.code;
			newline();
			cout<<"\nName: ";
			cin.getline(yourCust[j].order.item.name, 19);
			cout<<"\nPrice: ";
			cin>>yourCust[j].order.item.price;
			newline();
			cout<<"\nQuantity: ";
			cin>>yourCust[j].order.quantity;
		}
	}

		cout<<"\nSUMMARY REPORT";
		cout<<setw(10) <<"\n#";
		cout<<setw(16) <<"Customer Name";
		cout<<setw(21) <<"Order Date";
		cout<<setw(25) <<"Items";
		cout<<setw(30) <<"Price";
		cout<<setw(10) <<"Quantity";

		for (int k=0; k<1; k++)
		{
			
			cout<<endl;
			cout<<setw(10) << k+1;
			cout<<setw(16) <<yourCust[k].name.lastName<<", "<<yourCust[i].name.firstName;
			cout<<setw(21) <<yourCust[k].order.date.month<<"/"<<yourCust[i].order.date.day<<"/"<<yourCust[i].order.date.year;
			cout<<setw(25) <<yourCust[k].order.item.name;
			cout<<setw(30) <<yourCust[k].order.item.price;
			cout<<setw(10) <<yourCust[k].order.quantity;
		}
		
		cout.setf(ios::fixed);
		cout.setf(ios::showpoint);
		cout.precision(2);
		
		system("pause>0");
		return 0;
}

void newline(){
	char s;
	do{
		cin.get(s);
	}while (s!='\n');
}
One of the errors is the use of both k and i as subscripts at line 89 onward.

You can get the compiler to help you detect this problem by removing the declaration of int i; at line 41, and then change line 43 like this:
for (int i=0; i<1; i++)
Now at line 89, variable i doesn't exist, and the compiler will tell you so, if you accidentally attempt to use it. Though in keeping with the overall structure, there should probably be an inner for loop nested within the loop where the report is generated.
Topic archived. No new replies allowed.