So here I have this void function, which will add the number of students that are within a specific range. The ranges are 1-50,50-100,100-200. Again, the user will enter in all the test scores and then this function will store in the total amount of students within a certain range.
My problem! I'm using this void function in this other void function. I'm getting an error on cout<<"a\n\n\A total of " <<fiftytohundred<< were recorded.. fiftytohundred as an error saying its undefined How do I remedy this issue?
1 2 3 4 5 6 7 8 9 10 11 12
//Function: Will sort out the user scores and place them in to certain ranges. 1-50,50-100,100-200
void scorerangeadder (int score, int &sco_one_to_fifty, int &sco_fifty_to_hundred,int &hundred_to_hundred)
{
if (score>0 || score<=50)
sco_one_to_fifty++;
elseif (score >50 && score <=100)
sco_fifty_to_hundred++;
elseif (score >100 && score <=200)
hundred_to_hundred++;
}
void inputtestscores( int list[],int size, int &studentnumber)
{
int index=0;
cout<<"\n\n\tUser Input: ";
for (index=0;index<size;index++)
{
cout<<"\n\t\t";
do
{
cin>>list[index];
if (list[index]<0 || list[index]>200)
cout<<"\nIncorrect";
//Call the function: Scorerangeadder to determine the range
//Declare a variabel to store the scores
int scores=list[index];
int onetofifty;
int fiftytohundred;
int hundredtohundred;
scorerangeadder(scores,onetofifty,fiftytohundred,hundredtohundred);
}
while (list[index]<0 || list[index]>200);
studentnumber++;
}
//Output the total number of students within each range
cout<<"\n\n\A total of " << fiftytohundred << " were recorded in this range. ";
Just curious, If I can't use that then can you give me a hint of how I can record the total number of students within each range using another void function? I don't want to pile up all of my code uner one function :)
So your saying that void functions will not work inside another void function
void functions will work inside void functions, BUT not inside the << operator :
1 2 3 4 5 6 7 8
void inputtestscores( int list[],int size, int &studentnumber)
{
//-- call fiftytohundred() function :
fiftytohundred(); // this is perfectly valid, you can call a void function w/in the void function
//-- but
cout << fiftytohundred(); // error!! fiftytohundred has NO return value, you cannot call it inside cout <<.
}
Shadowfiend I think we have a litte misunderstanding. fiftytohundred is not a function. Its a reference parameter of the function void score range adder. here is my function for this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//Function: Will sort out the user scores and place them in to certain ranges. 1-50,50-100,100-200
void scorerangeadder (int score, int &sco_one_to_fifty, int &sco_fifty_to_hundred,int &hundred_to_hundred)
{
if (score>0 || score<=50)
sco_one_to_fifty++;
elseif (score >50 && score <=100)
sco_fifty_to_hundred++;
elseif (score >100 && score <=200)
hundred_to_hundred++;
}