New to c++. I want to take the input values in scoreCurrent
and place them into different arrays depending on whether they're above the average or below the average. I tried looking for solutions from different websites and youtube but none worked so far. How do I do this?
I apologize if my whole code is a mess and thank you in advance.
#include <iostream>
using namespace std;
int main()
{
// student count
int students, upperLimit;
cout<<"Enter no. of students: ";
cin>>students;
// upper limit
do
{
cout<<"Enter the upper limit: ";
cin>>upperLimit;
if(upperLimit<5)
{
cout<<"Invalid upper limit."<<endl;
continue;
}
break;
}while(true);
// student scores
int scoreCurrent, scoreTotal;
float average=0;
int belowAve(students), aboveAve(students);
for(int index=1; index<=students; index++)
{
cout<<"Enter score for student no. "<<index<<": ";
cin>>scoreCurrent; // take this and place it into an array
// condition invalid
if(scoreCurrent>upperLimit || scoreCurrent<0)
{
int current=index-1;
cout<<"Invalid score."<<endl;
index=current;
scoreCurrent=0;
}
scoreTotal+=scoreCurrent;
average=(float) scoreTotal/(float) students;
if(scoreCurrent>average)
{
// scoreCurrent values are placed in belowAve array;
}
if(scoreCurrent>average)
{
// scoreCurrent values are placed in aboveAve array;
}
}
// display
cout<<"Average: "<<average<<endl;
cout<<"Scores above or equal average: "<<belowAve<<endl;
cout<<"\nScores below average: "<<aboveAve<<endl;
return 0;
}