Nov 25, 2013 at 2:08pm UTC
@chervil Uhm, actually i was asking how will i let the items inputted by the first customer show up? First customer's items aren't showing up properly.
I removed the [2] after name, thanks bout that. The real prob is items of the 1st cust. Pleas guide me! Thanks.
Nov 25, 2013 at 4:15pm UTC
Something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
for (int i=0; i<2; i++)
{
cout<<endl;
cout<<setw(5) << i+1
<<setw(12) <<yourCust[i].name.lastName<<", " <<yourCust[i].name.firstName
<<setw(4) <<yourCust[i].order.date.month<<"/" <<yourCust[i].order.date.day<<"/" <<yourCust[i].order.date.year;
cout<<"\n" ;
for (int j=0; j<2; j++)
{
cout<<setw(19)<<"\t\t\t"
<<setw(9) <<yourCust[i].order.item[j].name
<<setw(14) <<yourCust[i].order.item[j].price
<<setw(16) <<yourCust[i].order.item[j].quantity
<<endl;
}
}
Last edited on Nov 25, 2013 at 4:16pm UTC
Nov 26, 2013 at 12:57am UTC
@chervil Cool. How am i going to output the price? Thanks, the item of the 1st customer now outputs properly. My only last problem is, the total price of both two customers. Please guide me~! Thanks! :)
my code now looks like this :) :
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 130 131 132 133
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
struct Customer{
struct {
char firstName[20];
char lastName[20];
}name;
char contactNo[20];
struct {
struct {
int code;
char name[20];
double price;
int quantity;
}item[2];
struct {
int day;
int month;
int year;
}date;
}order;
};
void newline();
int main()
{
Customer yourCust[2];
cout<<"Enter 2 customers." ;
for (int i=0; i<2; i++)
{
system ("cls" );
cout<<"\n\nCUSTOMER INFORMATION " <<(i+1)<<endl;
cout<<"\nFirst Name: " ;
cin.getline(yourCust[i].name.firstName, 19);
cout<<"\nLast Name: " ;
cin.getline(yourCust[i].name.lastName, 19);
cout<<"\nContact No: " ;
cin.getline(yourCust[i].contactNo, 19);
cout<<"\n\nOrder Date." ;
cout<<"\nDay: " ;
cin>>yourCust[i].order.date.day;
cin.ignore();
cout<<"\nMonth: " ;
cin>>yourCust[i].order.date.month;
cin.ignore();
cout<<"\nYear: " ;
cin>>yourCust[i].order.date.year;
cin.ignore();
for (int j=0;j<2;j++)
{
cout<<"Enter 2 items." ;
cout<<"\n" <<j+1<<" ITEM" ;
cout<<"\nID: " ;
cin>>yourCust[i].order.item[j].code;
cin.ignore();
newline();
cout<<"\nName: " ;
cin.getline(yourCust[i].order.item[j].name, 19);
cout<<"\nPrice: " ;
cin>>yourCust[i].order.item[j].price;
cin.ignore();
newline();
cout<<"\nQuantity: " ;
cin>>yourCust[i].order.item[j].quantity;
cin.ignore();
}
system ("cls" );
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\nSUMMARY REPORT\n" ;
cout<<setw(5) <<"#" ;
cout<<setw(20) <<"Customer Name" ;
cout<<setw(12) <<"Order Date" ;
cout<<setw(12) <<"Items" ;
cout<<setw(14) <<"Price" ;
cout<<setw(17) <<"Quantity" ;
for (int j=0; j<2; j++)
{
double totalPrice = yourCust[j].order.item[j].price * yourCust[j].order.item[j].quantity;
}
for (int i=0; i<2; i++)
{
cout<<endl;
cout<<setw(5) << i+1
<<setw(12) <<yourCust[i].name.lastName<<", " <<yourCust[i].name.firstName
<<setw(4) <<yourCust[i].order.date.month<<"/" <<yourCust[i].order.date.day<<"/" <<yourCust[i].order.date.year;
cout<<"\n" ;
for (int j=0; j<2; j++)
{
cout<<setw(19)<<"\t\t\t"
<<setw(9) <<yourCust[i].order.item[j].name
<<setw(14) <<yourCust[i].order.item[j].price
<<setw(16) <<yourCust[i].order.item[j].quantity
<<endl;
}
double totalPrice = yourCust[i].order.item[i].price * yourCust[i].order.item[i].quantity;
cout<<setw(16) <<"TOTAL PRICE: "
<<setw(18) <<totalPrice
<<endl;
}
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' );
}
Last edited on Nov 26, 2013 at 12:57am UTC
Nov 26, 2013 at 11:47am UTC
I started to give an answer regarding totalPrice, but then I noticed that it is calculated twice, at line 93 and line 114. Before going any further, you need to get rid of one or other of those, as it just causes confusion.
Set the total to zero. Then loop through the order items for that customer, calculate the cost and add it to the total. Make sure you use different subscripts for customer and order.
Nov 26, 2013 at 1:03pm UTC
@chervil thanks, it works well now! :)