# Finding the lowest score

Again I don't know if I am calling it correctly.

Thank you!

#include
using namespace std;

int getNumAccidents ();
void findLowest (int,int,int,int,int);

int main()

{
int acc1, acc2, acc3, acc4, acc5;

cout << "Enter The Number Of Automobile Accidents Reported A Year
";
cout << "By Region And I Will Show you The Region With The Fewest Accidents
";
cout << "North
";
cin >> acc1;
cout << "South
";
cin >> acc2;
cout << "East
";
cin >> acc3;
cout << "West
";
cin >> acc4;
cout << "Central
";
cin >> acc5;

getNumAccidents ();
{
int acc1,acc2,acc3,acc4,acc5;

if (acc1, acc2, acc3, acc4, acc5 < 0)
cout << "Accidents Must Be Equal or Greater Than 0
";
}

cout<< " The Region With The Least Accidents Is: " << endl;

findLowest(acc1, acc2, acc3, acc4, acc5);

return 0;
}
int acc1,acc2,acc3,acc4,acc5;
void findLowest(int,int,int,int,int)

{
if (acc1 < acc2,acc3,acc4,acc5)

{
cout << "North Is The Region With The Least Accidents With" << acc1 << endl;
}

if (acc2 < acc1,acc3,acc4,acc5)
{
cout << "South Is The Region With The Least Accidents With" << acc2 << endl;
}

if (acc3 < acc1,acc2,acc4,acc5)
{
cout << "East Is The Region With The Least Accidents With" << acc3 << endl;
}

if (acc4 < acc1,acc2,acc3,acc5)
{
cout << "West Is The Region With The Least Accidents With" << acc4 << endl;
}

if (acc5 < acc1,acc2,acc3,acc4)
{
cout << "Central Is The Region With The Least Accidents With" << acc5 << endl;
}

else
{
cout << "There Are More Than One Region With The Same Ammount Of Accidents" << endl;
}
}

• First of all, the functions must be defined outside main(). Second, the function parameters are copies of the ones in main(), so they don't necessarily need to have the same name, but they need to have some kind of name. For convenience, I picked the same names in the example below, but you could as well have named them a1, a2, a3 etc.

Also, you compare the variables in the wrong way. An if-statement contains no built-in intelligence at all, you have to compare all variables one by one. Meaning that will be a long tiresome code... it is much easier to do this when you know how to handle arrays.

You should have something like this:

[code]void findLowest (int acc1, int acc2, int acc3, int acc4, int acc5);

int main()
{
int acc1, acc2, acc3, acc4, acc5;
...
findLowest(acc1, acc2, acc3, acc4, acc5);
...
}

void findLowest (int acc1, int acc2, int acc3, int acc4, int acc5)
{
if(acc1 < acc2 && acc1 < acc3 && acc1 < acc4 && acc1 < acc5)
{
cout << ...
}
else if(acc2 < acc1 && ....)
{
}

}[/code]
• : First of all, the functions must be defined outside main(). Second,
: the function parameters are copies of the ones in main(), so they
: don't necessarily need to have the same name, but they need to have
: some kind of name. For convenience, I picked the same names in the
: example below, but you could as well have named them a1, a2, a3 etc.
:
: Also, you compare the variables in the wrong way. An if-statement
: contains no built-in intelligence at all, you have to compare all
: variables one by one. Meaning that will be a long tiresome code...
: it is much easier to do this when you know how to handle arrays.
:
: You should have something like this:
:
:
: [code]: void findLowest (int acc1, int acc2, int acc3, int acc4, int acc5);
:
: int main()
: {
: int acc1, acc2, acc3, acc4, acc5;
: ...
: findLowest(acc1, acc2, acc3, acc4, acc5);
: ...
: }
:
: void findLowest (int acc1, int acc2, int acc3, int acc4, int acc5)
: {
: if(acc1 < acc2 && acc1 < acc3 && acc1 < acc4 && acc1 < acc5)
: {
: cout << ...
: }
: else if(acc2 < acc1 && ....)
: {
: }
:
: }[/code]:

So, what happens with the getNum? I am supposed to use that to get the number of accidents and then output with the findLowest...
• I just showed how to use functions in C, but it should be something similar.

If/when you know how to use arrays and pointers, that code will be so much smoother. It will then be something like this:

[code]int findLowest (int* acc, int size)
{
int lowest;
int i;

lowest = acc[0];

for(i=1; i<size; i++)
{
if(acc[i] < lowest)
{
lowest = acc[i];
}
}

return lowest;
}[/code]