Hello, I am relatively new to the C++ world and I had a question about passing strings to a function.
This is a homework question and I do not want any solutions but I would like a hint or even to know if this can be done.
It is listed here:
http://www3.delta.edu/donaldsouthwell/cst180/cst180_Lab07.htm
The problem consists of entering 5 different regions (North, South, East, West, and Central). 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 each city region.
I was doing north = getNumAccidents("North") and using the function like so:
int getNumAccidents(char section) // passing "North"
{
cout << "How many automobile accidents were reported in the " << section << " sector last year? ";
cin >> numAccidents;
if (numAccidents < 0)
{
cout << "Values cannot be less than zero. Please try again.\n";
cout << "How many automobile accidents were reported in the " << section << " sector last year? ";
cin >> numAccidents;
}
return numAccidents;
}
This is giving me a slew of errors.
Any ideas how to pass a string to a function to get an int?
Brian