Help with asking user to input numbers?

Just to be clear, I chose Computer Programming as a minor, because I thought it would be interesting. Turns out I have absolutely no clue what I'm doing, and I don't belong here. Point is, sorry if this is a dumb question.

I need to ask the user to input numbers. "Write a program, which will ask the user how many whole numbers they wish to enter. The program will then read that many numbers, print them in the order they were entered, sort them in order by increasing value, and print them in sorted order.
All numbers entered and displayed will be integer values."

So far, this is not working. I thought this was how you do it. What am i doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

using namespace std;

#include "BubbleSort.h"

void main ()
	{
	
	int Nums;
	int		Array [20] = {Nums};
	int		i;

	cout << "Put in numbers: " << endl; 
	cin >> Nums; 
	cout << "Original Array is ";
	for (i = 0; i < 10; i++)
		cout << Array [i] << ' ';
	cout << endl;
	BubbleSort (Array, 10);
	cout << "Sorted Array is   ";
	for (i = 0; i < 10; i++)
		cout << Array [i] << ' ';
	cout << endl;
	}


I probably will change my minor, but for now I missed the drop date, so I'm stuck witch this class.

Thanks in advance for any help you can provide
Hi, sorry to hear about your feelings, I imagine a lot of people new to programming feel that way but I can tell you that if you stick with it, and give it a honest go, you'll start to love it, or at least appreciate it and what it can do for you.

I don't know where you got it, but void main () is NOT valid, use int main () instead.

I'm new to C++ too, and I don't see what is wrong with your code and don't know what BubbleSort is but this page will get you started with a working array.
http://www.cplusplus.com/doc/tutorial/arrays/

From there you can modify it to do what you need I think.

Here is a page talking about bubblesort
http://tycoontalk.freelancer.com/coding-forum/84466-c-bubble-sort.html

Last edited on
Sorry to hear about your situation but I agree with SamuelAdams, stay with it and you will like it. Now back to your code:

On line 10 Nums currently contain nothing so when you put it into
Array [20] = {Nums};
you put nothing into the 1st element of the array. If I read your question correctly then Nums should be the amount of numbers you want to enter then you would need another for loop to read in those numbers. So before read out the unsorted array create a for loop to read in those numbers, for example:
1
2
3
4
5
for (int index = 0; index < Nums; index++)
{
    cout << "Enter a number: ";
    cin >> Array[index];
}


This loop would allow the user to enter how many numbers they wished based on Nums.

Another thing is when I ran your code, my complier cannot find "BubbleSort.h" so I do not know if you have a header file for BubbleSort or not but I do know that there is no implementation of BubbleSort in the standard library, but I could be wrong.

P.S. If there any mistake, please forgive me.
Topic archived. No new replies allowed.