Hello all,
I am just starting out programming and have an assignment due in the near future. the problem is I cant seem to figure it out. I started it already but got stuck cant seem to figure it out. Here is the assignment.
Create a program that will generate a list of 200 random numbers (ranging from 1-1000) and determine the medium, mode, and average of the list of numbers. Have the program display the original list ant then display the list in ascending and descending order on the screen.
Well, I can write this program for you, but It might be better if you figure it out. I can help you out another way. Im guessing you want to write it in C++.
1. Find the rand() function. Many websites and forums on it.
2. You want the list of numbers to be stored in some sort of data structure, maybe an array or vector; those two are probably the most basic ones. Find how to declare and iterate through arrays/vectors.
#include <cstdlib> //You will need this for the function rand()
#include <ctime> //You will need this for the random 'seed'
int array[200] //This declares an array that can store 200 integers.
array[5] = rand() % 1000 + 1; //This will make array element 5 a random number 1-1000.
array[1] = rand() % 1000 + 1; //This will make array element 1 a random number 1-1000..
//To find the average, you just need to add all numbers up and divide by 200.
//Numbers add and divide like this.
int total = 0;
total = array[5] + array[1]; //Add the two random numbers.
total = total / 2; //Divide by two to find the average of those two numbers.
//To find the mode and the median, you will need to do a sort algorithm. Here I am
//not sure if you an use STL or must you write your own algorithm?