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

int getNumAccidents() is passed the name of a region. It asks the user for the number of automobile accidents reported in that region during the last year, validates the input. then returns it. It should be called once for every 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 figures.


my current code:

#include <iostream>
using namespace std;

	int getNumAccidents();
	void findLowest();
	int north, south, east, west, central

int main()
{
	cout << "There will be 5 major geographic regions within the major city.\n"
		<< "Please answer the question for each region.";
	cout << "The firts region is the north";
	getNumAccidents();
	north = getNumAccidents();
	cout << "The next region is the south.";
	getNumAccidents();
	south = getNumAccidents();
	cout << "The next region is the east.";
	getNumAccidents();
	east = getNumAccidents();
	cout << "The next region is the west.";
	getNumAccidents();
	west = getNumAccidents();
	cout << "The next region is the central.";
	getNumAccidents();
	central = getNumAccidents();
	findLowest();


}

int getNumAccidents()
{
	int accidents = 0;

	cout << "How many automobile accidents were reported\n"
		<< "in the region during the last year?";
	cin >> accidents;

	if (accidents < 0)
	{
		cout << "ERROR: please enter a positive number";
		cin >> accidents:
	}
	return  accidents;
}

void findLowest()
{

Right now i'm stuck on the method of finding the lowest value and how i would associate that value with one of the regions. so pretty much the void findLowest() section

consider this:

int count = 0;
int min = 32767;
for (i=0;i<count;i++)
{
if (number[count]<min)
min = number[count];
}//end of i
cout<<"Minimum # is"<<min<<endl;

i got the two errors:
error C2065: 'i' : undeclared identifier
error C2065: 'number' : undeclared identifier

i added:
int number[100];

to get rid of the first error, but i thought:
for (i=0;i<count;i++)

would declare the identifier. i havent tested the actual code yet.

An alternate method that doesn't rely on using an array to hold each value read in and doesn't use some large number for the initial value of min would be to assign the first value entered to the variable holding smallest value entered. Then with each subsequent value entered compare it with the current smallest value and current value is smaller than current smallest value assign current value to smallest value. If you are going to use the values read in for other analyses then holding them in a container (like an array) is a good idea.

for (i=0;i<count;i++)

i needs to be declared before it is used in this statement.

I was planing on doing that which i know would make this all that more simple, but because of

void findLowest() is passed the five accident totals.

i don't believe i can do that..
so im guessing the array may be the way to go with this. im just not too sure yet how.

int main()
{
    int smallest;
    cout << "The firts region is the north";
    smallest = getNumAccidents();
    
     
    cout << "The next region is the south";
    south = getNumAccidents();
    findLowest(smallest, south);

    cout << smallest;
}

void findLowest(int & smallest, int x)
{
   //determine if x is smaller than smallest
   //if so assign x to smallest
   //since smallest is a reference, the current value f smallest will be retained back in main
}
int main()
{
    const int MAX;
    int values[MAX];
    //load data into values here
    
    int smallest;
    findLowest(smallest, values);
    
    cout << smallest;
}

void findLowest(int & smallest, int * values)
{
    smallest = values[0];
    for(int i = 1; i < MAX; ++i)
    {
       //determine if current element of values is smaller than smallest
       //if so, then assign current element of value to smallest
     }
}

Given the description of findLowest() using an array is probably the desired. Also, given the description of findLowest() you can declare smallest in findLowest() and not bother passing it to findLowest() since findLowest() will print it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.