C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 1st, 2006, 02:52 AM
jdory18 jdory18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 3 jdory18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 11 sec
Reputation Power: 0
Unhappy Lowest drop help (im such an idiot)

I have a program that i need to write where i have to make the program drop the lowest score of five test scores. I just cant get figure out the ending to the program. This is what i have so far:

#include <iostream>
#include <iomanip>
using namespace std;

//Function Prototype
void getValues();
void findLowest();
void calcAverage();

int main()
{
cout << "This program shows the full use of using
functions ";
cout << "to calculate the average of a series of
tests.";
getValues(); // The first function called
findLowest(); // This function is called
second
calcAverage(); // Lastly, the third function
is called
cout << "Now, that is how you calculate the average
of a ";
cout << "series of tests.";
return 0;
}

//**********************************************
// Definition of function getValues. *
// This function asks for five test scores and *
// stores them in variables. *
//**********************************************

void getValues()
{
int score1, score2, score3, score4, score5;

cout << "Enter in 5 test scores and I will store ";
cout << "them in variables. ";
cin >> score1 >> score2 >> score3 >> score4 >> score5;
cout << fixed << showpoint << setprecision(2);
}

//************************************************** *****
// Definition of function findLowest. *
// This function determines which out of those *
// five test scores is the lowest and return that value *
//************************************************** *****

void findLowest()
{
int score;
double lowest;

"Out of the five test scores the lowest score is " <<
lowest << endl;
lowest = score1

Reply With Quote
  #2  
Old November 1st, 2006, 08:44 AM
Paul820 Paul820 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Location: United Kingdom
Posts: 428 Paul820 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 7 h 55 m 4 sec
Reputation Power: 13
Can't you use an array with a loop to get the lowest score? Otherwise it will be very messy with a lot of if else statements.

Reply With Quote
  #3  
Old November 1st, 2006, 09:41 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
From a quick look,
you need to put the variables score1, ...., score5 outside and before any function so that can be globally accessible! As for the findLowest() function, you need to have an array, here's something that might work:
Code:
void findLowest()
{
      int array[5];
      array[0] = score1;
      array[1] = score2;
      array[2] = score3;
      array[3] = score4;
      array[4] = score5;
      int lowest=999999;
      for(int i=0;i<5;i++)
       {
             if(array[i] < lowest)
                   lowest = array[i];
       }
cout<<"The lowest is "<<lowest<<endl;
}


Hope I helped!!

Costas

Reply With Quote
  #4  
Old November 1st, 2006, 09:31 PM
jdory18 jdory18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 3 jdory18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 11 sec
Reputation Power: 0
So will this execute?

// This program will calculate the value of
// five test scores and drop the lowest.
#include <iostream>
#include <iomanip>
using namespace std;

//Function Prototype
void getValues();
void findLowest();
void calcAverage();

int main()
{
cout << "This program shows the full use of using
functions ";
cout << "to calculate the average of a series of
tests.";
getValues(); // The first function called
findLowest(); // This function is called
second
calcAverage(); // Lastly, the third function
is called
cout << "Now, that is how you calculate the average
of a ";
cout << "series of tests.";
return 0;
}

//**********************************************
// Definition of function getValues. *
// This function asks for five test scores and *
// stores them in variables. *
//**********************************************

void getValues()
{
int score1, score2, score3, score4, score5;

cout << "Enter in 5 test scores and I will store ";
cout << "them in variables. ";
cin >> score1 >> score2 >> score3 >> score4 >>
score5;
cout << fixed << showpoint << setprecision(2);
}

//************************************************** *****
// Definition of function findLowest. *
// This function determines which out of those *
// five test scores is the lowest and return that value *
//************************************************** *****

void findLowest()
{
int array[5];
array[0] = score1;
array[1] = score2;
array[2] = score3;
array[3] = score4;
array[4] = score5;
int lowest=999999;
for(int i=0;i<5;i++)
{
if(array[i] < lowest)
lowest = array[i];
}
cout<<"The lowest is "<<lowest<<endl;

Reply With Quote
  #5  
Old November 1st, 2006, 11:22 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 14
Send a message via AIM to ubergeek
I don't know, will it? The best way to test your code is to...test it. Put it in the compiler, and click the Compile/Run button. If it doesn't run, look at the errors and see if you can make sense of them. If you can't, ask us for help (but make sure to tell us the exact error message.) For example, if you were to compile your code with GCC it would complain about an "unexpected end of file" (other compilers will have slight variations of wording). Can you see why (hint: how do you end a function)?

Once you get the code to compile, it may crash while running or just print out incorrect values. Then you should have the program tell you where is it going wrong -- pepper the program with cout statements telling you the result of various calculations so you can spot mistakes.

Reply With Quote
  #6  
Old November 2nd, 2006, 04:49 AM
Paul820 Paul820 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Location: United Kingdom
Posts: 428 Paul820 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 7 h 55 m 4 sec
Reputation Power: 13
You can use an array and then pass the address of the array along with the array's size. There is no need to use global variables.

Like this:

Code:
#include <iostream>
#include <iomanip>
using namespace std;

//Function Prototype
void getValues();
void findLowest( int testScore[], int sz );
void calcAverage();

int main()
{
    cout << "This program shows the full use of using functions ";
    cout << "to calculate the average of a series of tests.";

    getValues(); // The first function called
    // findLowest(); // This function is called second
    // calcAverage(); // Lastly, the third function is called

    cout << "Now, that is how you calculate the average of a ";
    cout << "series of tests.";

    return 0;
}

//**********************************************
// Definition of function getValues. *
// This function asks for five test scores and *
// stores them in variables. *
//**********************************************

void getValues()
{
    const int size = 5;
    int scores[size];

    cout << "Enter in " << size << " test scores and I will store ";
    cout << "them in variables.\n";

    for ( int i = 0; i < size; i++ )
    {
        cout << "Enter score " << ( i + 1 ) << " : ";
        cin >> scores[i];
    }

    findLowest( scores, size ); // pass the address and size of the scores array

    cout << fixed << showpoint << setprecision(2);
}

//**************************************************   *****
// Definition of function findLowest. *
// This function determines which out of those *
// five test scores is the lowest and return that value *
//**************************************************   *****

void findLowest( int testScore[], int sz )
{
    int lowest = testScore[0]; // make the first element of the array the lowest.
                               // loop through the array and compare the rest with
                               // first element.

    for ( int i = 0; i < sz; i++ )
    {
        if ( testScore[i] < lowest )
        {
            lowest = testScore[i];
        }
    }

    cout << "The lowest is " << lowest << endl;
}


You should be able to figure the rest out for yourself
Use code tags, highlight the code you want and then click on the # icon to wrap in code tags. Makes your code easier to read.

Reply With Quote
  #7  
Old November 5th, 2006, 04:42 PM
jdory18 jdory18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 3 jdory18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 11 sec
Reputation Power: 0
Thanks everyone! I got it.

Reply With Quote
  #8  
Old November 30th, 2009, 11:40 AM
usamainadv usamainadv is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: US
Posts: 3 usamainadv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 2 sec
Reputation Power: 0
Hi there!

Hi,My name is Allan.I'm excited to be part of this large and growing forum of great people and thankyou all for making me feel welcome. I just joined today.My special interests or skills are:- HTML- SEO- Web design- Internet businessI am happy to help others that need it and offer advice where possible

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Lowest drop help (im such an idiot)


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap