So I need help on array problems and i have to ask the user for their name, phone number, 5 test scores, the average of their test scores and show in the output their lowest and highest scores. So far I have this:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
string pnumber;
string address;
double scores[4];
int i;
double avg;
int highest = 100, lowest= 0.0;
cout << "What is your name? ";
getline(cin, name);
cout <<"What is your phone number? ";
cin >> pnumber;
//get input
for (i=0;i<=4; i++)
{
cout << "\nPlease enter your scores: ";
cin >> scores[i];
}
Oh ok that seems to make sense! And what I was talking about is out of the 5 test scores entered my the user, the program will return the highest and lowest test scores.
cout << "What is your name? ";
getline(cin, name);
cout <<"What is your phone number? ";
cin >> pnumber;
//Get Input
for (int i = 1; i <= 5; i++)
{
cout << "Please enter score " << i << ": ";
cin >> scores[i];
avg += scores[i];
for ( int i = 1; i < 5; i++ )
{
if ( scores[i] < lowest ) lowest = scores[i];
if ( highest < scores[i] ) highest = scores[i];
}
}
avg /= 5;
cout << "The highest score is: " << highest << endl;
cout << "The lowest score is: " << lowest << endl;
cout << "The average score is: " << avg << endl;
return 0;
}
and when I enter the test scores it comes out like this:
What is your name? Bob
What is your phone number? 555-555-5555
Please enter score 1: 1
Please enter score 2: 2
Please enter score 3: 3
Please enter score 4: 4
Please enter score 5: 5
The highest score is: 1.07591e+43
The lowest score is: 0
The average score is: 3