Finding lowest score

Hi, I am trying to find the lowest score out of a group of 5 but for some reason it keeps telling me my lowestScore variable is undeclared even though I set to equal to 0.


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

//////////////////////////////////////
// Prototypes
//////////////////////////////////////
void displayWelcome();
void getPerformer(string&, int&, string&);
void getJudgesScores(double&, double&, double&, double&, double&);
double findLowest(double&, double&, double&, double&, double&);





int main()
{
//variables
string name;
int age = 0;
string talent;
double score1 = 0;
double score2 = 0;
double score3 = 0;
double score4 = 0;
double score5 = 0;
double lowestScore = 0;




//Call the functions
displayWelcome();
getPerformer(name, age, talent);
getJudgesScores(score1, score2, score3, score4, score5);
findLowest(score1, score2, score3, score4, score5);


return 0;

}

//////////////////////////////////////
// Function Definitions
//////////////////////////////////////

void displayWelcome()
{
cout << "Welcome to The National Star Search Competetion" << endl;
}

void getPerformer(string& tempName, int& tempAge, string& tempTalent)
{
cout << "May I have your name please" << endl;
cin >> tempName;
cout << "May I have your age please" << endl;
cin >> tempAge;
cout << "What is your talent?" << endl;
cin >> tempTalent;
cout << tempName << tempAge << tempTalent << endl;
}

void getJudgesScores(double& tempScore1, double& tempScore2, double& tempScore3, double& tempScore4, double& tempScore5)
{
cout << "What is the first score?" << endl;
cin >> tempScore1;
if (tempScore1 < 0 || tempScore1 > 10)
{
cout << tempScore1 << "is invalid" << endl;
cout << "Enter a score between 0 and 10" << endl;
cin >> tempScore1;
}

cout << "What is the second score?" << endl;
cin >> tempScore2;
if (tempScore2 < 0 || tempScore2 > 10)
{
cout << tempScore2 << "is invalid" << endl;
cout << "Enter a score between 0 and 10" << endl;
cin >> tempScore2;
}

cout << "What is the third score?" << endl;
cin >> tempScore3;
if (tempScore3 < 0 || tempScore3 > 10)
{
cout << tempScore3 << "is invalid" << endl;
cout << "Enter a score between 0 and 10" << endl;
cin >> tempScore3;
}

cout << "What is the fourth score?" << endl;
cin >> tempScore4;
if (tempScore4 < 0 || tempScore4 > 10)
{
cout << tempScore4 << "is invalid" << endl;
cout << "Enter a score between 0 and 10" << endl;
cin >> tempScore4;
}

cout << "What is the fifth score?" << endl;
cin >> tempScore5;
if (tempScore5 < 0 || tempScore5 > 10)
{
cout << tempScore5 << "is invalid" << endl;
cout << "Enter a score between 0 and 10" << endl;
cin >> tempScore5;
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
double findLowest(double& tempScore1, double& tempScore2, double& tempScore3, double& tempScore4, double& tempScore5)
{
     while (tempScore1 < tempScore2 && tempScore1 < tempScore3 && tempScore1 < tempScore4 && tempScore1 < tempScore5)
     {
            lowestScore = tempScore1;
            return lowestScore;
     }
     while (tempScore2 < 1 && tempScore2 < 3 && tempScore2 < tempScore4 && tempScore2 < tempScore5)
     {
      
           lowestScore = tempScore2;
           return lowestScore;
     }
     while (tempScore3 < tempScore1 && tempScore3 < tempScore2 && tempScore3 < tempScore4 && tempScore3 < tempScore5)
     {
            lowestScore = tempScore3;
            return lowestScore;
     }
     while (tempScore4 < tempScore1 && tempScore4 < tempScore2 && tempScore4 < tempScore3 && tempScore4 < tempScore5)
     {
            lowestScore = tempScore4;
             return lowestScore;
     }
     while  (tempScore5 < tempScore1 && tempScore5 < tempScore2 && tempScore5 < tempScore3 && tempScore5 < tempScore4)
     {
            lowestScore = tempScore5;
             return lowestScore;
     }
            
}
lowestScore is defined inside main(), but not inside findLowest(), where it is being used.
Should I remove the tempscores and put templowestScore inside findLowest?
I think you should put them in an array and sort it so its not that ugly...

no idea if this would work but try using 0.0 instead of just 0 ?
THE PROGRAM U HAV DESIGNED APPEARS TO BE QUITE CLUMSY HERE IS ONE FOR U WHICH IS SMALL AND EFFECTIVE AS WELL HOPE IT HELPS

#include<iostream.h>
#include<stdio.h>
class participant
{float mrks[5], lowest;
char name[20], talent[10];
int age;
float lowestmrk();
Public:
void welcome();
void getscores();
}
void participant :: welcome()
{ cout<<"Enter the name"<<endl;
gets(name);
cout<<"Enter age=";
cin>>age;
cout<<"Enter talent"<<endl;
gets(talent);
}
float participant :: lowestmrk()
{ lowest = m[1];
for( int i=2; i<=5; i++)
{if(m[i]>lowest)
lowest = m[i];
}
return (lowest);
}
void participant :: getscores()
{float l;
for(int i=1; i<=5; i++)
{cout<<"Enter the marks of judge"<<i;
cin>>m[i];
if(m[i]>10)
cout"Enter the marks btw 0 and 10=":
cin>>m[i];
}
l=lowest()
cout"Enter lowest n=marks given="<<l;
}
void main()
{
paticipant p;
p.welcome();
p.getscores();
}


Hey computerdude: For a pretty easy fix, try declaring the 'lowestScore' variable as a global variable. Declare it outside any other functions, close to your pre-processor directives, or where your constant definition section would be, before int main.

This would ensure that it is available for use in any function. Also, global variables are automatically assigned a "place-holder" value, so you would not need to set it equal to 0 immediately. You could wait until you actually need to use it for a specific value, and then just assign that value to the variable, or change the variable value then.
Topic archived. No new replies allowed.