### Test Scores Arrays

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?

 ``123456789101112`` ``````//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++; else if (score >50 && score <=100) sco_fifty_to_hundred++; else if (score >100 && score <=200) hundred_to_hundred++; }``````

 ``1234567891011121314151617181920212223242526272829`` ``````void inputtestscores( int list[],int size, int &studentnumber) { int index=0; cout<<"\n\n\tUser Input: "; for (index=0;index>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. ";``````
Last edited on
line 29 is the error line...
I'm not looking for answers, just looking for a guidance towards the answer. So anyone willing to help please :)
add parenthesis: `<< fiftytohundred() << `

Edit no wait, i've just read that fiftytohundred() is a `void`, and you cannot call a void function inside << since it has no return value
Last edited on
So your saying that void functions will not work inside another void function? only returning value functions would work? correct?
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 :

 ``12345678`` ``````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 <<. }``````

can you post your fiftytohundred() function ?
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.

 ``1234567891011121314`` ``````//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++; else if (score >50 && score <=100) sco_fifty_to_hundred++; else if (score >100 && score <=200) hundred_to_hundred++; } ``````
oh, sorry, i didn't see that, well your problem is scope issues, the compiler cannot see fiftytohundred because you declared it inside the loops.

Try moving `int fiftytohundred` outside the do-while and for loop