im confused

based on the notes that i saw ,how to make input and output in nested structure ,im confuse which one should begin with ,some notes start with customer and some are not ,

struct computer
{
char brand[20];
char serial_no[30];
int year_produce;
};

struct customer
{
char name[20];
char email[20];
computer favouriteComputer;
}adam;
The order usually doesn't matter as long as you use the same order for both output and input.
any suggestion???
is this ok???

#include<iostream>
using namespace std;

struct computer
{
char brand[20];
char serial_no[30];
int year_produce;
};

struct customer
{
char name[20];
char email[20];
computer favouriteComputer;
}adam;

int main ()
{
cout<<"Enter name : ";
cin>>adam.name;
cout<<"Enter email : ";
cin>>adam.email;
cout<<favouriteComputer : " ;
cin>>adam.favouriteComputer;

cout<<"brand:"<<adam.brand<<"serial_no:"<<serial_no<<endl;
cout<<"year_produce:"<<year_produce<<"/"<<year_produce<<"/"<<year_produce<<endl;

return 0;
}
This looks like a duplicate of:

http://www.cplusplus.com/forum/general/227064/

Please don't post multiple threads on the same topic.

I've already posted an answer on the other thread.
I thought you were going to serialize it to be stored in a file, sent over a network, or something like that. For what you are doing here you can ignore what I said in my previous post because the output is not meant to be used as input later on.

If you want cin>>adam.favouriteComputer; to work you need to overload the >> operator to work with objects of type computer. Not sure that's what you want though. You will in any case have to write the code to read input to set the brand, serial_no and year_produce fields pretty much like you have done with the name and email of costumer.
1
2
3
4
cout << "Enter brand of Adam's favourite computer: ";
cind >> adam.favouriteComputer.brand;
cout << "Enter serial number of Adam's " << adam.favouriteComputer.brand << " computer: ";
...
Last edited on
Registered users can post here. Sign in or register to post.