I'm not asking anyone at all to write the code for me or anything like that, just some pointers on where to start and what to think about when writing the functions. I apologize ahead of time if this kind of question isn't really suitable.
use srand function to get random numbers in a range : rangevalue = (rand() % (nHigh - nLow + 1)) + nLow; (this will generate a number withing the range nLow and nHigh whenever you call it and assign it to variable rangevalue) dont forget to put srand(time(0)); at beggining of main function so the numbers can be random and include the library <ctime>
Thanks for the help but I've got that part down already. The trouble I'm having with that particularly is getting getScore to give a randomized score whose range is set in getStats only a certain of times. Any hints on how I can get that started?
int limits[2]; // declare an array for min and max of the range
getStats(limits); // use function getStats with array as param.
void getStats( int *limits); // dont forget you must use pointers *
{
cin >> limits[1]; // min
cin >> limits[2]; // max
}
//now you use array limits for int getScore (dont forget about pointer *)
It's really difficult to tell what's going on in that code. You can you lay out a step by step what you're trying to accomplish? Do you get the range from a user? Or manually input them? Then what? just generate some scores within that range? Explain the problem better. Here are a couple observations though
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <ctime> // needed to for time
usingnamespace std;
//Declare secondary functions before main
void printGradeRange(double meanScore);
void getStats(double &meanScore);
int getScore();
int main() {
srand(int(time(0))); // Seed for rand
//This needs to be initialized to some value
//before passing it to printGradeRange
//As it is, this will not compile
double totalMean;
printGradeRange(totalMean);
system("pause");
return 0;
}
/*Functions*/
//Random Score Generator
int getScore()
{
return (rand());
}
//Calculated Mean and Standard Deviation
void getStats(double &meanScore)
{
cout.precision(2);
int getScore();
//double N = 10.0; // Why are you initializing to 10 here? and then.....
double totalScore = 0.0, randomScore1 = 0.0, randomScore2 = 0.0;
//for (N = 10; N>0; N--) Initializing to 10 here?
//do this
for (int n = 10; n > 0; n--){// and why did it need to be a double instead of int?
if (n > 4){
randomScore1 = (getScore() % 101);
cout << randomScore1 << endl;
}
else {
randomScore2 = (getScore() % 30 + 40);
cout << randomScore2 << endl;
totalScore += randomScore2;
}
totalScore += randomScore1;
meanScore = (totalScore / n);
}
}
//Print: Scores Generated, Mean, Std, and Range
void printGradeRange(double meanScore)
{
cout.precision(2);
//Don't put return-type before function call
//if You want to pass by reference, then the function prototype needs
//a reference paramater, then you just plug in the variable to ref. Don't put
//& before arguement in the call. And again, no data type in front of arguments.
getStats(meanScore);
double givenMean;
getStats(givenMean);
cout << fixed << meanScore << endl;
}
The range is supposed to be previously set in getStats. Everytime getStats calls getScore, getScore will randomly generate a number within the range set in getStats. Then within getStats the mean of all the scores generated is calculated.
Then in printGradeRange, it is supposed to print all the scores and the mean.
Got it now, though not completely. Will have to do for now. Thanks to all who replied. :)