I have this program that I made but for some reason I cannot get the program to reject any number below 1. Also I want to make sure I have at least an array, loop, and a function in the program. Any help would be great.
Here is the code:
#include <iostream>
#include <algorithm>
using namespace std;
void Average(int *arr, int n){
double avg = 0.0;
for(int i=0;i<n;++i){
avg = avg + arr[i];
}
cout<<"The Average score is: "<<avg/n<<endl;//Calculates the average for scores inserted
}
void Highest(int *arr, int n){
int highest = 0;
for(int i=0;i<n;++i){
while(highest < arr[i])
highest = arr[i];//Calculates the highest score
}
cout<<"The Highest score is: "<<highest<<endl;//Shows user the highest score
}
void Lowest(int *arr, int n){
int lowest = 100;
for(int i=0;i<n;++i){
while(lowest > arr[i])//Loop for the lowest number
lowest = arr[i];//Calculates lowest score
}
cout<<"The Lowest score is: "<<lowest<<endl;//Shows user the lowest score
}
int main()
{
int n;
cout <<"How many students: ";//Asks user to enter amount of students scores
cin>>n;
int arr[n];
cout<<"Enter "<<n<<" Scores"<<endl;
int i;
for(i=0;i<n;++i){
When I input 0 it will not give me lowest 0, but it will give me highest 0 and the average nan. I tried changing the int lowest 100 to 0 like the highest but whenever I insert numbers like say the program asks for the students and the user inputs 2 students. The program will then ask for the test scores and say the user inserts 3 and 5 for the scores. It will say the highest is 5, the average is 4, but the lowest 0 because when i put int lowest=0. However, int highest=0 does exactly what i want it to do
2) Do you genuinely not know if you have an array in your code?
Do you genuinely not know if you have a loop in your code?
Do you genuinely not know if you have a function in your code?
If you really don't know what any of those things is, to the extent that you don't even know if you'ce got one in your code, then your time would probably be better spent going back to your textbook, and re-reading the appropriate section on that thing.