sentinel terminated loop/avg calculation

This is a discussion on sentinel terminated loop/avg calculation within the C++ Programming forums, part of the General Programming Boards category; I am working on this program and I need to add two things to it, first I need the program ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    12

    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];
    
    	char grade;
    	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)
    			grade='A';
    		 else if (avg >= 83.0)
    			grade='B';
    		 else if (avg >= 74.0)
    			grade='C';
    		 else if (avg >= 65.0)
    			grade='D';
    		else
    		    grade='F';
             
    		
            
            		
    		}
    
               
    
    	cout << lastName<< " , " << firstName << " " << setw(6) << setprecision(2) 
    		<< "Average:" << avg << " " 
    		                                  << "Grade:" << grade << endl;
    
    		return (0);
    
    }

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    First,

    use here

    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    instead of
    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. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    12
    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;
    
    	char grade;
    	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)
    			grade='A';
    		 else if (avg >= 83.0)
    			grade='B';
    		 else if (avg >= 74.0)
    			grade='C';
    		 else if (avg >= 65.0)
    			grade='D';
    		else
    		    grade='F';
             
    		
            
            		
    		}
    
               
    
    	cout << lastName<< " , " << firstName << " " << setw(6) << setprecision(2) 
    		<< "Average:" << avg << " " 
    		                                  << "Grade:" << grade << endl;
    
    		return (0);
    
    }

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    12
    Okay, I reread my instructions and finally figured this program out. I had to make several changes, well actually rewrite the entire thing. I was way off base!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sentinel controlled repetition example
    By droseman in forum C Programming
    Replies: 7
    Last Post: 09-26-2008, 02:17 AM
  2. Problem with sentinel values
    By Golfduffer in forum C Programming
    Replies: 3
    Last Post: 08-30-2007, 01:19 AM
  3. Help with calculation and loop
    By Betty in forum C Programming
    Replies: 7
    Last Post: 04-10-2006, 05:37 AM
  4. Sentinel while loop and errors.
    By lollypop in forum C Programming
    Replies: 12
    Last Post: 10-19-2003, 12:40 PM
  5. while, sentinel, if, switch
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-11-2001, 10:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21