Hi there,
I'm really new with programming, I haven't done any before this class I am taking now, so I'm really struggling.
I know it's really simple, but I'm having a lot of trouble figuring out how to do my next assignment. I've tried writing it down in pseudocode, but I just don't think I understand so it's not helping me. This is my assignment:
"Write and test a C++ program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in order from largest to smallest. Note, the sentinel number is not to be considered as one of the numbers, it should not be printed."
Right now I am just trying to figure out how to do the part that talks about putting the numbers into an array and quitting when a negative is entered, without including the negative in the array. It's really confusing me, nothing I have tried is working.
I would like to concentrate on this part by itself right now, if possible I'd like to just forget about the sorting right now.
**I know there is a LOT wrong with this code, you don't need to tell me!** I just wanted to put it there so it's known I'm actually trying to do this and not just trying to get people to do my homework for me. I know it's embarrassing and horrible so please don't say much about it. Haha
But if someone could talk me through putting numbers in an array and stopping with a negative, without putting the negative in the array, that would be absolutely fantastic.
Thank you!!
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 26 27
|
#include <iostream>;
using namespace std;
int main()
{
int i, array[10];
for (i=0; i<=9; i++)
{
cout << "\nEnter a number: ";
cin >> i;
if (i>=0)
{
i=array[i];
}
else
{
cout << "\nNumbers are " << array[i];
//i want it to print all numbers except negative
//butnopenopenope
//killmenow
}
}
return 0;
}
|