7 Replies - 785 Views - Last Post: 31 March 2009 - 08:38 AM Rate Topic: -----

#1 webbywebb  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 30-January 07

How to output what from stored an array

Posted 30 March 2009 - 06:01 PM

how would i store the values in arrays, and put my input in a loop with a counter for the index in the array.

This post has been edited by webbywebb: 30 March 2009 - 06:02 PM

Is This A Good Question/Topic? 0
  • +

Replies To: How to output what from stored an array

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,556
  • Joined: 23-August 08

Re: How to output what from stored an array

Posted 30 March 2009 - 06:27 PM

Google C++ arrays
Was This Post Helpful? 0
  • +
  • -

#3 IrishCereal  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 81
  • Joined: 11-December 08

Re: How to output what from stored an array

Posted 30 March 2009 - 08:34 PM

Arrays have to be filled and displayed by individual element. I like to use a for loop. So something like this.
int array[10]; //initialize array with 10 elements
for(int ii = 0; ii < 10; ++ii) { 
  array[ii] = ii + 1;  //fill array with 1-10
  cout << array[ii] << endl; // print each element on one line per element
}



Above is just a simple snippet that will fill an array with 1-10 and print out each number. You can manipulate it to do whatever you need though. :)

View PostJackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:

Google C++ arrays


Replies like this really bother me. Sure, the answer probably is posted somewhere on the web, but that doesn't mean you have to post a completely helpless reply like this.
Was This Post Helpful? 0
  • +
  • -

#4 webbywebb  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 30-January 07

Re: How to output what from stored an array

Posted 30 March 2009 - 09:12 PM

View PostIrishCereal, on 30 Mar, 2009 - 07:34 PM, said:

Arrays have to be filled and displayed by individual element. I like to use a for loop. So something like this.
int array[10]; //initialize array with 10 elements
for(int ii = 0; ii < 10; ++ii) { 
  array[ii] = ii + 1;  //fill array with 1-10
  cout << array[ii] << endl; // print each element on one line per element
}



Above is just a simple snippet that will fill an array with 1-10 and print out each number. You can manipulate it to do whatever you need though. :)

View PostJackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:

Google C++ arrays


Replies like this really bother me. Sure, the answer probably is posted somewhere on the web, but that doesn't mean you have to post a completely helpless reply like this.


oh i c thanks so much, i understand now but whats bothering me is how would i get the user to input into that array
Was This Post Helpful? 0
  • +
  • -

#5 prabhakar.balakrishna  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 21
  • Joined: 17-March 09

Re: How to output what from stored an array

Posted 30 March 2009 - 09:58 PM

View Postwebbywebb, on 30 Mar, 2009 - 08:12 PM, said:

View PostIrishCereal, on 30 Mar, 2009 - 07:34 PM, said:

Arrays have to be filled and displayed by individual element. I like to use a for loop. So something like this.
int array[10]; //initialize array with 10 elements
for(int ii = 0; ii < 10; ++ii) { 
  array[ii] = ii + 1;  //fill array with 1-10
  cout << array[ii] << endl; // print each element on one line per element
}



Above is just a simple snippet that will fill an array with 1-10 and print out each number. You can manipulate it to do whatever you need though. :)

View PostJackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:

Google C++ arrays


Replies like this really bother me. Sure, the answer probably is posted somewhere on the web, but that doesn't mean you have to post a completely helpless reply like this.


oh i c thanks so much, i understand now but whats bothering me is how would i get the user to input into that array




You can modify the code as follows to make the user to enter


 int a[100],n;
 cout<<"Please Enter Number of elements of array";
 cin>>n;

// Reads n elements 
 for(int i = 0 , i <n;i++)
{
 cout<<" enter element "<<(i+1);
 cin>>a[i];
 } 


Hope this will helpful





Was This Post Helpful? 0
  • +
  • -

#6 webbywebb  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 30-January 07

Re: How to output what from stored an array

Posted 30 March 2009 - 10:45 PM

View Postprabhakar.balakrishna, on 30 Mar, 2009 - 08:58 PM, said:

View Postwebbywebb, on 30 Mar, 2009 - 08:12 PM, said:

View PostIrishCereal, on 30 Mar, 2009 - 07:34 PM, said:

Arrays have to be filled and displayed by individual element. I like to use a for loop. So something like this.
int array[10]; //initialize array with 10 elements
for(int ii = 0; ii < 10; ++ii) { 
  array[ii] = ii + 1;  //fill array with 1-10
  cout << array[ii] << endl; // print each element on one line per element
}



Above is just a simple snippet that will fill an array with 1-10 and print out each number. You can manipulate it to do whatever you need though. :)

View PostJackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:

Google C++ arrays


Replies like this really bother me. Sure, the answer probably is posted somewhere on the web, but that doesn't mean you have to post a completely helpless reply like this.


oh i c thanks so much, i understand now but whats bothering me is how would i get the user to input into that array




You can modify the code as follows to make the user to enter


 int a[100],n;
 cout<<"Please Enter Number of elements of array";
 cin>>n;

// Reads n elements 
 for(int i = 0 , i <n;i++)
{
 cout<<" enter element "<<(i+1);
 cin>>a[i];
 } 


Hope this will helpful






here is my code
#include "stdafx.h"
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::endl;
using std::cin;
int main()
{
	int n = 0;
	int capa[5], size;
	char name[30];
	char userchoice;
	int sold;
Inputsection:

	cout << "Hello, Welcome to the movie purchase services:" << endl;
	cout << "Please enter a Movie name? Please indicate when you want to stop typing with a %" << endl;
	cin.getline(name, 30, '%');
	
	cout << "The Movie that you entered was:" << name << endl;
	cout << "What is the ticket capacity for this movie?" << endl;
	cin >> size;
	   // Reads n elements
	for(int i = 0; i <n;i++)
 {
   cout<<" enter element "<<(i+1);
  cin>>capa[i];
  } 
   	

	cout << "The movie capacity for this movie is:" << size << endl;

	cout << "The number of tickets that are sold for this movie are:" << endl;
	cin >> sold;
		cout << " Would you like to add additonal Information? [Y/N]" << endl;
		cin >> userchoice;
	   
	  if (userchoice == 'y')
	 {
		goto Inputsection;
	 }	
	if (userchoice == 'n')
	{
		for( int i = 0; i < 5; i++ ) {
	   capa[i] = i + 1; 
	   cout << capa[i] << endl;
	}
	  
   system("PAUSE");
	return 0;
}

 }


Sample Input and Output:
Enter a movie name: Mummy II
Enter its ticketing capacity: 500
Enter number of the tickets sold: 492

Additional data (Y/N)? Y

Enter a movie name: Meet the Parents
Enter its ticketing capacity: 600
Enter number of the tickets sold: 600

Additional data (Y/N)? N
if the user does not want to continue, the program then outputs what is already stored. which is:

Movie/Capacity/Tickets Sold/Seats Available
------------------------------------------------------
Mumm II/500/492/8
Meet the Parents/600/600/0

this is what i want to do but i am bothered by this. i am not sure what to do.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,556
  • Joined: 23-August 08

Re: How to output what from stored an array

Posted 31 March 2009 - 05:23 AM

Quote

View PostJackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:

Google C++ arrays

Replies like this really bother me. Sure, the answer probably is posted somewhere on the web, but that doesn't mean you have to post a completely helpless reply like this.

It's not completely helpless. Give a man a fish, teach a man to fish, you know?

Fact is, just giving someone the answer to such an easily answered question -- although that is what this and so many of the people who come here actually want -- is not helping them at all; it's enabling them. Look at this user's next post:

Quote

oh i c thanks so much, i understand now but whats bothering me is how would i get the user to input into that array

While the user says he/she understands, that's not the case at all. If they would actually just expend a little thought, a light might go off and it may suddenly become clear to them. All they see is that you did not directly answer the question exactly as they wanted, with code they could just drop into their project.

So then we have the next user attempting to be helpful, prabhakar.balakrishna, who gives some more example code that more pointedly addresses the problem of gathering user input into the array -- but again, not exactly what the user wants -- and we see the result...a post of the OP's code along with exactly what he/she's supposed to do, and the code received from this helpful poster just copied and pasted into the program without any thought or attempt at understanding by the OP.

In the end, the OP has progressed minimally, if at all, and perhaps has just become more confused. In fact, the OP has done very little at all in the two weeks since first posting looking for help with this program, and demonstrates in another thread that they really just want their homework done for them.
Was This Post Helpful? 0
  • +
  • -

#8 IrishCereal  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 81
  • Joined: 11-December 08

Re: How to output what from stored an array

Posted 31 March 2009 - 08:38 AM

View PostJackOfAllTrades, on 31 Mar, 2009 - 04:23 AM, said:

Quote

View PostJackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:

Google C++ arrays

Replies like this really bother me. Sure, the answer probably is posted somewhere on the web, but that doesn't mean you have to post a completely helpless reply like this.

It's not completely helpless. Give a man a fish, teach a man to fish, you know?

Fact is, just giving someone the answer to such an easily answered question -- although that is what this and so many of the people who come here actually want -- is not helping them at all; it's enabling them. Look at this user's next post:

Quote

oh i c thanks so much, i understand now but whats bothering me is how would i get the user to input into that array

While the user says he/she understands, that's not the case at all. If they would actually just expend a little thought, a light might go off and it may suddenly become clear to them. All they see is that you did not directly answer the question exactly as they wanted, with code they could just drop into their project.

So then we have the next user attempting to be helpful, prabhakar.balakrishna, who gives some more example code that more pointedly addresses the problem of gathering user input into the array -- but again, not exactly what the user wants -- and we see the result...a post of the OP's code along with exactly what he/she's supposed to do, and the code received from this helpful poster just copied and pasted into the program without any thought or attempt at understanding by the OP.

In the end, the OP has progressed minimally, if at all, and perhaps has just become more confused. In fact, the OP has done very little at all in the two weeks since first posting looking for help with this program, and demonstrates in another thread that they really just want their homework done for them.



Touche, sir. I know what you're saying now. I guess I just didn't understand where you were coming from on the first post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1