The assignment calls for me to find the area with the fewest accidents (north, south, east, west, central) in a city. I am to write two functions:

-getNumAccidents() is passed the name of the region. It asks user for the number of auto accidents in the region, validates info, and returns it. It should be called once for each region.

-void findLowest() is passed the five accident total. It determines which is the smallest and prints the name of the region, along with accident figure.

I wrote first function in a cout/ cin line asking for user input of the region, as well as the accident total from that region. I am unsure as to what would be the easiest way to find the lowest amount. I do not want to use an array in this program, because we have not gone over them in C++, only java...

>I am unsure as to what would be the easiest way to find the lowest amount.

#include <iostream>

using namespace std;

int main()
{
  int vals[] = {234, 3, 4, 45, 4};

  int lowest = 10000; //some large value

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

  cout << lowest << endl;

  cin.get();
}

Hi since..:

I do not want to use an array in this program, because we have not gone over them in C++, only java...

let imagine your code :) :) :

...
int main()
{
......
for ( int i = 0 ; i < 5; i++ )
{
   int noAccidents = getNumAccidents(area);
   int areanumber = findlowest(noAccidents );
}
switch(areanumber )
{
case 1:
       cout<<"North area of town has the lowest no of accidents: "<<noAccidents ;
case 2:
       cout<<"Southarea of town has the lowest no of accidents: "<<noAccidents ;
.....
default:
..}
///functions implementations:
......
int getNumAccidents(const string& regionName)
{
//your implementation
}

int findLowest(const int& numberOfAccidents )
{
  int temp = 5000; //a very big number of accidents :D
  int saveIndex=0;
  if (numberOfAccidents < temp);
          {
          temp=numberOfAccidents ;
          saveIndex=i;
          }
 return saveIndex;
}
.....
return 0;
}

good luck :D

So much help, so little correct :icon_rolleyes:

To find the lowest value, store the first value read in a variable, say lowest. Then for each successive read, test the value read against lowest and replace if necessary.

So much help, so little correct

Maybe u should post at 2 am too, to see how correct your solution would be..... :D

This article has been dead for over six months. Start a new discussion instead.