Oct 4, 2014 at 12:55pm UTC
Hello!
(Using windows, codeblocks, c++)
I'm trying to make a program to do following!
Make functions for:
//1. Ask user for sequence lenght: 0 <= k <= 300
Validate input
//2. Ask user to enter a sequence of integers
Store the integers in an array
//3. Display sequence by the same order they are entered and max 6 per line
I cannot use any loops in the main.
Can anybody help? :)
Last edited on Oct 4, 2014 at 12:59pm UTC
Oct 4, 2014 at 1:03pm UTC
Yes. But i cannot make it work..
Have not used arrays outside main before.
Oct 4, 2014 at 1:22pm UTC
YES! Something like that!! :) :) thank you!!
i'm not sure how i call the function in the main?
Oct 4, 2014 at 1:27pm UTC
int getSequenceLength(void);
void storeIntergerInAnArrayFunction(int);
Are these global variables? Or what do these say??
Oct 4, 2014 at 1:28pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13
type function(type,..) // function prototype
int main()
{
function(someVariable,..); // if you write what you named the funtion in the main function
// we say that you called the function
}
type function(type,...) // function body or implementation
{
// some code
}
hope that helped
Last edited on Oct 4, 2014 at 1:28pm UTC
Oct 4, 2014 at 1:36pm UTC
Trying to do something like this, but now the main does not work!!
# include <iostream>
using namespace std;
int Sequence_Length(int seq_length)
{
do{
cout << "Enter the sequence length: ";
cin >> seq_length;
if(seq_length >= 0 && seq_length <= 300)
break;
}
while (seq_length >= 0 && seq_length <= 300);
return seq_length;
}
void storesequence(int seq[], int n)
{
cout << "Please enter the sequence of integers: " << endl;
for(int i=0;i<n;i++)
{
cin >> seq[i];
}
for(int i=0;i<n;i++)
{
cout << seq[i] << " ";
}
}
int main()
{
storesequence(Sequence_Length());
return 0;
}
[/output]
Oct 4, 2014 at 1:45pm UTC
read some turorials first instead of gambling http://www.cplusplus.com/doc/tutorial/functions/
Last edited on Oct 4, 2014 at 1:45pm UTC