# Thread: sentinel terminated loop/avg calculation

1. ## sentinel terminated loop/avg calculation

I am working on this program and I need to add two things to it, first I need the program to accept many students names and scores (not just one) and add a sentinel terminated loop which the loop terminates when the students first name is "light" and last name is "truth". Also, on the student average calculation, I need to be able to drop the lowest score and count the highest score twice for example if the score were: 90 80 70 70 80, I would drop one of the 70's and count the 90 twice. I am really confused, any help would be greatly appreciated!

Code:
#include <iostream.h>
#include <iomanip.h>

int main()

{
char firstName[25];
char lastName[25];
float score[5];

float avg=0.0;
float totScore=0.0;
int x=0;
int y=0;

cout << "Enter student's first name, last name, and five scores:";
cin >> firstName >> lastName;

for (x=0; x<5; x++)
{
cin >> score[x];

}

for (y=0; y<5; y++)

totScore += score[y];
avg = totScore/5;
{

if (avg >= 92.0)
else if (avg >= 83.0)
else if (avg >= 74.0)
else if (avg >= 65.0)
else

}

cout << lastName<< " , " << firstName << " " << setw(6) << setprecision(2)
<< "Average:" << avg << " "

return (0);

}

2. First,

use here

Code:
#include <iostream>
#include <iomanip>

using namespace std;
Code:
#include <iostream.h>
#include <iomanip.h>
is a start..

Also use the string class instead of an array of chars- it will make your life much easier.

Make changes and repost.
Mr. C.

3. Okay I put in the strings and tried to declare a struct, but I am getting two errors. I have added comments in the program.

Code:
#include <iostream>
#include <iomanip>

using namespace std;

int main()

struct StudentRec//wouldn't I have to declare a struct declaration?
{//here I get unexpected end of file error and syntax error missing ';' before '<class-head>'
string firstName;
string lastName;
string score;

float avg=0.0;
float totScore=0.0;
int x=0;
int y=0;

cout << "Enter student's first name, last name, and 5 scores:";
cin >> firstName >> lastName;

for (x=0; x<5; x++)
{
cin >> score[x];

}

for (y=0; y<5; y++)

totScore += score[y];
avg = totScore/5;
{

if (avg >= 92.0)
else if (avg >= 83.0)
else if (avg >= 74.0)
else if (avg >= 65.0)
else

}

cout << lastName<< " , " << firstName << " " << setw(6) << setprecision(2)
<< "Average:" << avg << " "