lowest test score

This is a discussion on lowest test score within the C++ Programming forums, part of the General Programming Boards category; Thank you so much for the tips................. Brownie...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    1

    Lightbulb lowest test score

    Thank you so much for the tips.................

    Brownie
    Last edited by brown34; 05-12-2002 at 08:21 AM.

  2. #2
    Registered User OxYgEn-22's Avatar
    Join Date
    Apr 2002
    Posts
    36
    ughh... can you put that in code braces please next time!!

    ok, your problem is that the function scopes out and you loose all your data because you have not returned it back to main!! I see you are confused with the right way to use functions. you see, the ( braces ) send information to your function, and your return will send back the information.


    1. Your predefs have a vairable name, this is not neccesary because all you need to see is the type of variable, like so

    void calcAverage(int test1, int test2, int test3, int test4, int test5, int lowest);

    -to-

    void calcAverage(int , int , int , int , int , int );


    2. Are you trying to use pointers or references here:

    void getValues(int& test1, int& test2, int& test3, int& test4, int&
    test5)

    3. not void main, int main the the correct way


    this is my edited code of yours, it works but there may be a few advanced things running around in there :

    Code:
    #include <iostream.h> 
    
    struct tests
    {
    	int test1;
    	int test2;
    	int test3;
    	int test4;
    	int test5;
    };
    
    //Function Prototype 
    tests getValues(); 
    int findlowest(tests); 
    void calcAverage(tests, int); 
    
    
    
    int main() 
    { 
    	tests marks;
    
    	marks = getValues(); 
    	calcAverage(marks, findlowest(marks)); 
    
    return 0;
    }
    
    tests getValues()
    { 
    
    	tests marks;
    
    	cout << "Enter first test score\n"; 
    	cin >> marks.test1;
    
    	cout << "Enter second test score\n"; 
    	cin >> marks.test2;
    
    	cout << "Enter third test score\n"; 
    	cin >> marks.test3;
    
    	cout << "Enter fourth test score\n"; 
    	cin >> marks.test4; 
    
    	cout << "Enter fifth test score\n"; 
    	cin >> marks.test5; 
    
    	return marks;
    } 
    
    int findlowest (tests lowest) 
    { 
    	int low; 
    
    	if (lowest.test1 < lowest.test2) 
    	{ 
    		low = lowest.test1; 
    	} 
    	else 
    	{
    		low = lowest.test2; 
    	} 
    
    	if (low > lowest.test3) 
    	{ 
    		low = lowest.test3; 
    	} 
    	if (low > lowest.test4) 
    	{ 
    		low = lowest.test4; 
    	} 
    	if (low > lowest.test5) 
    	{ 
    		low = lowest.test5; 
    	} 
    	return low; 
    
    } 
    
    void calcAverage(tests marks, int low) 
    { 
    	float average; 
    
    	average=((marks.test1 + marks.test2 + marks.test3 + marks.test4 + marks.test5) - low)/5.0; 
    	cout << "The average test score is: " << average;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting lowest and highest score from array
    By sjalesho in forum C Programming
    Replies: 6
    Last Post: 03-01-2011, 06:24 PM
  2. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 01:33 PM
  3. trouble with creating a loop to read certain number of inputs
    By import tuner650 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2008, 08:28 PM
  4. Lowest Score Drop - C++
    By getName(C-Dub) in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2008, 07:02 PM
  5. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 01:55 PM

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