GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-May-2008, 21:49
Mrehman Mrehman is offline
New Member
 
Join Date: Mar 2008
Posts: 23
Mrehman is on a distinguished road
Question

need some understanding on a question/need assisstance on for loop


hey guyz, i need some assistance understanding a question which i am totally confused about, and i need to know how to enter data while running a for loop. this is what the question is supposed to be doing..
Create an ARRAY of structs containing a member for name, age, and STATE for 10 people. Create a for loop to insert data for 5 people. Then create a for loop to display all data typed in, BY USER INPUT. Both for loops need to be INSIDE the main( ). this is what my code is so far
CPP / C++ / C Code:
 #include <iostream>
#include <string>
using namespace std;
 
struct Information
{
	string name;
	string age;
	string state;
	
	

};


void main()
{  
	Information Member[10];
	cout<<"Data for Member #1:"<<endl;
	Member[0].name = "Yun Li";
	Member[0].age  = "19";
	Member[0].state = "California";
	
	Member[1].name = "Rashad Brooks";
	Member[1].age  = "22";
	Member[1].state = "New York";
	
	Member[2].name = "Anthony Miller";
	Member[2].age  = "27";
	Member[2].state = "Vermont";
	
	Member[3].name = "Andre Mitchell";
	Member[3].age  = "20";
	Member[3].state = "Texas";
	
	Member[4].name = "Kevin Lucas";
	Member[4].age  = "33";
	Member[4].state = "Mississippi";
	
	for (int i=0;i<5;i++)
	{
		cout<<Member[i].name<<endl;
		cout<<Member[i].age<<endl;
		cout<<Member[i].state<<endl;	
	}
	
} 
i don't know what am i making a mistake in understanding. correct me if i am wrong please. i am suppose to create an array of struct for 10 people. then with the help of for loop i am suppose to enter data for 5 people. i am confused on this part run a for loop and enter data for 5 people. << this i don't exactly understand how to.
  #2  
Old 06-May-2008, 04:35
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: need some understanding on a question/need assisstance on for loop


CPP / C++ / C Code:
Information Member[10];


This is where you make a mistake.
  #3  
Old 06-May-2008, 07:31
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 761
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: need some understanding on a question/need assisstance on for loop


You are very close. I believe that the information is supposed to come from the user.

CPP / C++ / C Code:
#include <iostream>
#include <string>
using namespace std;
 
struct Information
{
	string name;
	string age;
	string state;
	
	

};


void main()
{  
	Information Member[10];
	int i;
/*
	cout<<"Data for Member #1:"<<endl;
	Member[0].name = "Yun Li";
	Member[0].age  = "19";
	Member[0].state = "California";
	
	Member[1].name = "Rashad Brooks";
	Member[1].age  = "22";
	Member[1].state = "New York";
	
	Member[2].name = "Anthony Miller";
	Member[2].age  = "27";
	Member[2].state = "Vermont";
	
	Member[3].name = "Andre Mitchell";
	Member[3].age  = "20";
	Member[3].state = "Texas";
	
	Member[4].name = "Kevin Lucas";
	Member[4].age  = "33";
	Member[4].state = "Mississippi";
*/
	for (i=0;i<5;i++)
	{
		cout << "Enter a name for user #" << i+1 << ": ";
		cin >> Member[i].name;
		
		// TODO: Get the age
		// TODO: Get the state
	}

	for (i=0;i<5;i++)
	{
		cout<<Member[i].name<<endl;
		cout<<Member[i].age<<endl;
		cout<<Member[i].state<<endl;	
	}
} 
  #4  
Old 06-May-2008, 10:29
Mrehman Mrehman is offline
New Member
 
Join Date: Mar 2008
Posts: 23
Mrehman is on a distinguished road

Re: need some understanding on a question/need assisstance on for loop


Hey thanks a lot. it helped.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:51.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.