I need some sort of variable that I can use to hold multiple integers and can print out basically. e.g
1 2 3 4
something userNumber = {a, b, c, d, e} // something along those lines.
cout << "Please enter 5 Number: " << endl;
cin >> userNumbers;
cout << "Your chosen numbers" << userNumbers << endl; // prints out the 5 numbers the user has entered.
char userNumbers[5];
cout << "\t Welcome, I will try to guess the minimum and maximum" << endl;
cout << "\t numbers of your chosen numbers." << endl;
cout << "\nPlease 5 Enter Your Numbers here: " << endl;
cin >> userNumbers;
cout << "Your Chosen Numbers: " << userNumbers;
But I have a problem.
When I enter the 5 numbers. The cout << "Your Chosen Numbers: " << userNumbers; part only outputs the first numbers that is entered, how can I make it so it outputs all 5 numbers?
This will try to store the input in userNumbers[5].... which does not exist. When you create an array of size 5, like this: char userNumbers[5];
the following array elements are created:
I note that you made an array of type char. Each element can hold one char object. Did you mean to make an array of type int?
cout << "Your Chosen Numbers: " << userNumbers;
This only works by chance because it's a char array. When you make it an int array, you will have to output each element individually. You need to go and read about arrays.
for(int i = 0; i < userNumbers; ++i)
{
cin >> userNumbers[i];
}
But then I get this error saying
ISO C++ forbids comparison between pointer and integer
Which I can't figure because I haven't even used a pointer, or have I even learnt them yet.
Btw way, with you putting ARRAY_SIZE; did you want me to put my char array userNumbers?
Thanks Cire :D I've now managed to nearly finish my program. But this code that I added to print out the chosen numbers.
1 2 3 4
for(int i = 0; i < 5; ++i)
{
cout << "Your Chosen Numbers: " << userNumbers[i] << endl;
}
Prints out like
Your chosen numbers: x
Your chosen numbers: y
etc..
Is there any other code that I can write to make print out the numbers on one line? i.e Your Chosen Numbers: x, y, etc..
Try to figure it out :)
What you want is to print "Your chosen numbers: " once, then cycle through the elements in the array and print each one of them (without printing a newline of course), then print a newline at the end of everything