Help writing program?

This is what I have to do...

Write a program that determines which of 5 geographic regions within a major city (north, south, east, west, and central) had the fewest and highest reported accidents last year. It should have the following three functions, which are called by main:

int getNumAccidents() is passed the name of a region. It asks the user for the number of accidents reported in that region during the last year, validates the input, then returns it. It should be called once for each city region.
void findLowest() is passed the five accident totals. It determines which is the smallest and prints the name of the region, along with its accident figure.
void findHighest() is passed the five accident totals. It determines which is the largest and prints the name of the region, along with its accident figure.
Input validation: Do not accept an accident number that is less than 0.

Use the following test data:

north 250

south 118

east 350

west 420

central 275


And here is what I have, but it is not working. Can someone point me in the right direction?

#include <iostream>
using namespace std;

//Function Prototypes
int getNumAccidents(int&, int&, int&, int&, int&);
void findLowest(int&, int&, int&, int&, int&);
void findHighest(int&, int&, int&, int&, int&);

int main()
{
int north, south, east, west, central;

//Call getNumAccidents to input the five numbers
getNumAccidents(north, south, east, west, central);

// call findLowest

//Display the highest and lowest

return 0;
}

int getNumAccidents(int &north, int &south, int &east, int &west, int &central)
{
cout << "Enter number of accidents in North, South, East, West, and Central, in that order: ";
cin >> north >> south >> east >> west >> central;
if (north < 1 || south < 1 || east < 1 || west < 1 || central < 1)
{ cout << " Invalid input, please make sure all numbers are positive and more than 0.";
cin >> north >> south >> east >> west >> central;
}

return 0;
}

void getLowest(int &north, int &south, int &east, int &west, int &central)
{
if (north < south && north < east && north < west && north < central)
cout << "North" << north;
else if (south < north && south < east && south < west && south < central)
cout << "South" << south;
else if (east < north && east < south && east < west && east < central)
cout << "East" << east;
else if (west < north && west < south && west < east && west < central)
cout << "West" << west;
else if (central < north && central < south && central < east && central < west)
cout << "Central" << central;

}

void getHighest(int &north, int &south, int &east, int &west, int &central)
{
if (north > south && north > east && north > west && north > central)
cout << "North" << north;
else if (south > north && south > east && south > west && south > central)
cout << "South" << south;
else if (east > north && east > south && east > west && east > central)
cout << "East" << east;
else if (west > north && west > south && west > east && west > central)
cout << "West" << west;
else if (central > north && central > south && central > east && central > west)
cout << "Central" << central;
}
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
using namespace std;

//Function Prototypes
int getNumAccidents(int&, int&, int&, int&, int&);
void findLowest(int&, int&, int&, int&, int&);
void findHighest(int&, int&, int&, int&, int&);

int main()
{
int north, south, east, west, central;

//Call getNumAccidents to input the five numbers
getNumAccidents(north, south, east, west, central);

// call findLowest

//Display the highest and lowest

return 0;
}

int getNumAccidents(int &north, int &south, int &east, int &west, int &central)
{
cout << "Enter number of accidents in North, South, East, West, and Central, in that order: ";
cin >> north >> south >> east >> west >> central;
if (north < 1 || south < 1 || east < 1 || west < 1 || central < 1)
{ cout << " Invalid input, please make sure all numbers are positive and more than 0.";
cin >> north >> south >> east >> west >> central;
}

return 0;
}

void getLowest(int &north, int &south, int &east, int &west, int &central)
{
if (north < south && north < east && north < west && north < central)
cout << "North" << north;
else if (south < north && south < east && south < west && south < central)
cout << "South" << south;
else if (east < north && east < south && east < west && east < central)
cout << "East" << east;
else if (west < north && west < south && west < east && west < central)
cout << "West" << west;
else if (central < north && central < south && central < east && central < west)
cout << "Central" << central;

}

void getHighest(int &north, int &south, int &east, int &west, int &central)
{
if (north > south && north > east && north > west && north > central)
cout << "North" << north;
else if (south > north && south > east && south > west && south > central)
cout << "South" << south;
else if (east > north && east > south && east > west && east > central)
cout << "East" << east;
else if (west > north && west > south && west > east && west > central)
cout << "West" << west;
else if (central > north && central > south && central > east && central > west)
cout << "Central" << central;
} 


Reposted to see the line numbers. Wrap in next time to make it easier to read.

Why are you returning something in getNumAccidents? That could just be void.
Last edited on
because the teacher asked us to make that an int
Ok nevermind that. What is going wrong? Can you explain?
I'm getting this and i'm not sure why.

>M6 Prog Challenge.obj : error LNK2019: unresolved external symbol "void __cdecl findHighest(int &,int &,int &,int &,int &)" (?findHighest@@YAXAAH0000@Z) referenced in function _main
1>M6 Prog Challenge.obj : error LNK2019: unresolved external symbol "void __cdecl findLowest(int &,int &,int &,int &,int &)" (?findLowest@@YAXAAH0000@Z) referenced in function _main
1>C:\Users\karas\Desktop\C++ Programming\M6 Prog Challenge\Debug\M6 Prog Challenge.exe : fatal error LNK1120: 2 unresolved externals

I think i'm going about this all wrong, but i'm not sure what to do.
When I compile and run your code I get no errors at all. It could be that in your function prototypes you are not giving your reference variables names. I use Dev C++.

Edit: Oh duh im blind. Your prototypes are findLowest and findHighest. When you define them, you use getLowest and getHighest. They have to be the same.
Last edited on
Is it giving you the right outputs when you input things?
And I use Microsoft Visual C++...and i'm not sure what is wrong with it.
You declare the functions as findHighest() etc, but define them as getHighest() etc. The definitions must match the declarations.
Lol I saw that right before you said it ModShop. Wonder how I didn't see that. LOL. Beat me too it.
Oh...I feel stupid. :l

Okay I fixed that...but I'm still having problems with it.
How do I get the main function to read from them?
you call them just like you did with getNumAccidents();
Ah! Okay...I tried that but it gave me an error...but I think I was doing something wrong.

Thank you very much!!! I think i've got it now. :D
Topic archived. No new replies allowed.