Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include using namespace std; int main() { //include directives int totalnorth,totalsouth,totaleast,totalwest; char region[10]; //getAccidentsinfo method definition int getAccidentsinfo(char re[]) { int tot; cout
#include
#include
#include
using namespace std;
int main()
{
//include directives
int totalnorth,totalsouth,totaleast,totalwest;
char region[10];
//getAccidentsinfo method definition
int getAccidentsinfo(char re[])
{
int tot;
cout
cin>>tot;
return tot;
}
//getChoice method definition
int getChoice()
{
int n;
coutDisplay safest region 2->Display least Safe region 3->Display all ";
cin>>n;
if(n
else
return n;
}
//findSafest method definition
void findSafest()
{
int least=totaleast;
char region[10];
if(totalsouth
else if(totalwest
else if(totalnorth
cout
}
//getleastSafe method definition
void findleastSafe()
{
int a=totalwest;
if(totaleast>a){a=totaleast;strcpy(region,"East");}
else
if(totalsouth>a){a=totalsouth;strcpy(region,"South");}
else
if(totalnorth>a){a=totalnorth;strcpy(region,"north");}
cout
}
//displayAll method definition
void displayAll()
{
cout
cout
cout
cout
}
//main method definition
void main()
{
int n;
clrscr();
//getting the accidents info usion getaccidents info method
totalnorth=getAccidentsinfo("north");
totalsouth=getAccidentsinfo("south");
totaleast=getAccidentsinfo("east");
totalwest=getAccidentsinfo("west");
//taking user choice
n=getChoice();
if(n==-1)cout
else
{
cout
//switch case statements for calling the methods according to the choice.
switch(n)
{
case 1: findSafest();cout
break;
case 2: findleastSafe();cout
break;
case 3: displayAll();cout
zyBooks My library CS 1336:Programming Fundamentals home 2.6 Hw6 zyBooks catalog @ Help/FAQ fa. HW6 (Graded out of 100) Write a program that prompts the user to enter traffic accident statistics for four geographic regions (north, south, east, and west), then displays a menu that lets the user choose from the following options 1. Display safest region 2. Display least safe region 3 Display all regions it the user chooses 1, the program should display the name of the safest region (north south east or west), along with the number of s the one with the lowest aooident total. Then the program prints 'Exiting and terminates f the user chooses 2, the program should display the name of the least safe region least safe region is the one with the highest accident total Then the program prints 'Exiting" and terminates f the user chooses 3, the program should display the name and number of ac east west. Then the program prints "Exiting and terminates f the user types an invalid choi along with the number of accidents of that region. The cidents for all the regions, in the following order north south oe, the program should display an error message Then the program prints "Exting' and terminates we will assume no two regions have the same sccident total and the user always inputs an int 1. Additional requirements - Make sure you meet all the requirements to avoid losing points . Make sure you follow the requirements in the Homeiork Notes The program should use the folowing furictions tem on the menu if the nout is vala returs me user's Choice Eise thernet on returns-1 Assume tre oer-wars enters an and do not ask the user to reenter an inout getAccidentTotal) his function s passed the name of a region north south east returns an int it displays the name of the region and promots the user to input the socident hotal for thet region The function euns the accident totsl Assume the input is awinys vd fndSafest) Ths furction is passed the four aocibent totals, determnes whioh is the getChoiceo disolays the menu of cholces, reads the uaer's chaice performa nout validastion An nputis velid only if t is equal to an or west) as an argument of type string and 7 8 9 5 6 break;
default:cout
break;
}
}
getch();
}//end of main
return 0;
}
This is my code but it's not working please help me fix it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started