When you post code, please use code tags. Highlight your posted code and click the Format button that looks like "<>". Or click the button first and paste your code between the generated tags. Using the code tags will make your code easier to read and comment on.
In the future,
please don't completely delete/replace your earlier posts. It makes responses appear cryptic. My initial response refers to the steps in your homework assignment which has now been removed.
The original steps referred to a maximum of 30 grades or some such, and stated that you needed an array
double Grades[x]
. Based on that step, I provided a couple of lines of code that are bit clumsy, but would meet that requirement. Without the context of your original post, my suggestion seems a bit akward at best.
//****Is there a better way to write the following line? by better I mean a simpler/more concise way ?
double value = 50 + static_cast <double> (rand()) /( static_cast <double>(RAND_MAX/(100-50))); |
For starters, you could simply generate random integers and cast them to doubles.
double value = 50 + (rand() % 51); // implicit cast from int to double
Using % 51 will yield values from 0 - 50 (inclusive), so adding 50 will give you all values from 50 - 100 (inclusive).
Again, because you removed your initial post, current readers will not understand why you need values here that are doubles and why the range from 50 - 100.
If your teacher requires something more that random integers casted to doubles, then you can improve your function later after you get the rest of the program working. My guess is that this code will be sufficient.
Ok how would I sort the grades from lowest to highest? haven't been able to figure that out yet. |
Are you required to sort the values? I don't believe that's what the assignment said. (Again, don't delete your initial post.) The comments in the code only say you need to find the average, highest and lowest values. You don't need to sort anything to find those values.