This post has been edited by webbywebb: 30 March 2009 - 06:02 PM
How to output what from stored an arrayi need help really bad.
Page 1 of 1
7 Replies - 627 Views - Last Post: 31 March 2009 - 08:38 AM
#1
How to output what from stored an array
Posted 30 March 2009 - 06:01 PM
Replies To: How to output what from stored an array
#2
Re: How to output what from stored an array
Posted 30 March 2009 - 06:27 PM
#3
Re: How to output what from stored an array
Posted 30 March 2009 - 08:34 PM
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.
JackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:
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.
#4
Re: How to output what from stored an array
Posted 30 March 2009 - 09:12 PM
IrishCereal, on 30 Mar, 2009 - 07:34 PM, said:
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.
JackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:
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
#5
Re: How to output what from stored an array
Posted 30 March 2009 - 09:58 PM
webbywebb, on 30 Mar, 2009 - 08:12 PM, said:
IrishCereal, on 30 Mar, 2009 - 07:34 PM, said:
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.
JackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:
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
#6
Re: How to output what from stored an array
Posted 30 March 2009 - 10:45 PM
prabhakar.balakrishna, on 30 Mar, 2009 - 08:58 PM, said:
webbywebb, on 30 Mar, 2009 - 08:12 PM, said:
IrishCereal, on 30 Mar, 2009 - 07:34 PM, said:
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.
JackOfAllTrades, on 30 Mar, 2009 - 05:27 PM, said:
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.
#7
Re: How to output what from stored an array
Posted 31 March 2009 - 05:23 AM
Quote
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
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.
#8
Re: How to output what from stored an array
Posted 31 March 2009 - 08:38 AM
JackOfAllTrades, on 31 Mar, 2009 - 04:23 AM, said:
Quote
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
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.
|
|

New Topic/Question
Reply




MultiQuote





|