OK, so I want to create a function getStrRegion(commented out at the bottom) to pass a str value N, S, E, W, C back to the main function so I can then drop it and regionSelect back into getNumAccidents.
I'm not exactly sure how to pass a string of characters around and just about every instance I've seen thus far just confuse me even more.
What's the best way to go about this?
#include <iostream>
#include <string>
using namespace std;
// function prototypes
int getNumAccidents(int regionSelect); //get region accident data; reguires user input regionSelect
void findlowest();
void showMenu();
int main()
{
int regionSelect, northNum = 0, southNum = 0, eastNum = 0, westNum = 0, centralNum = 0; // initializes @ 0 to perform while loop
cout << "***************************************************************************\n"
<< "** **\n"
<< "** Welcome to the Accident Reporting and Collection Datebase. **\n"
<< "** This interface allows you to store and display accident information **\n"
<< "** based on the respective regions of the Chicago Metropolitan area. **\n"
<< "** **\n"
<< "***************************************************************************\n\n";
while (northNum == 0 || southNum == 0 || eastNum == 0 || westNum == 0 || centralNum == 0) { // will continue until each region has a value
showMenu(); // jumps to showMenu function to show regions
cin >> regionSelect;
switch (regionSelect) { //switch statement to run function getNumAccidents until each region has a value > 0
case 1:
northNum = getNumAccidents(regionSelect);
break;
case 2:
southNum = getNumAccidents(regionSelect);
break;
case 3:
eastNum = getNumAccidents(regionSelect);
break;
case 4:
westNum = getNumAccidents(regionSelect);
break;
case 5:
centralNum = getNumAccidents(regionSelect);
break;
default: // 1-5 store a value in corresponding region, anything else errors
cout << "Invalid entry.\n";
break;
}
}
//findLowest();
return 0;
}
int getNumAccidents(int regionSelect) // value 1-5 is handed down
{
int accidentNum; // value returned from function
string region;
switch (regionSelect) { // converts 1-5 to a string in accident input
case 1:
region = "North";
break;
case 2:
region = "South";
break;
case 3:
region = "East";
break;
case 4:
region = "West";
break;
case 5:
region = "Central";
break;
}
cout << "\nPlease enter the number of reported accidents for the " << region << " region.\t";
cin >> accidentNum;
while (accidentNum <= 0) { // basic error checking returned value must be > 0
cout << "\nInvalid number! Please re-enter the number of reported accidents.\n";
cin >> accidentNum;
}
return (accidentNum);
}
void showMenu() // selection menu
{
cout << "\nPlease select the region:\n\n"
<< "1) North\n"
<< "2) South\n"
<< "3) East\n"
<< "4) West\n"
<< "5) Central\t";
}
/*
int getStrRegion(int regionSelect)
{
string region;
switch (regionSelect) {
case 1:
region = "North";
break;
case 2:
region = "South";
break;
case 3:
region = "East";
break;
case 4:
region = "West";
break;
case 5:
region = "Central";
break;
}
return (region);
}
*/