i want to add to this c++ code a condition so that you can only chose from - robbery, violation,medical, fire- if the user enterd something else the program should ask him to again chose from this service only... plz don't change the code alot just add .
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <time.h>
using namespace std;
const int size = 5 ;
string services [size]= {"Robbery ", "Violation ", "Medical ","Fire "};//The menu
string search;
string Thesrevice;
struct Info {
string name;
int age;
string location;
string AdditionalNote;
};
void Ask(string &z){// Function for Searching in array
cout<< "\n Your emergency?";
cout << endl;
cin>> z;
for (int i = 0 ; i< size ; i++){
if (services[i].find(z,0)!= string::npos){
cout<< "Your choice is "<< services[i]<<endl;
Thesrevice = services[i];
break;}
}}
void get_data(Info *array,int S){
cout<< "Enter Your name, age, location and any additional note"<<endl;
cin>> array[0].name>>array[1].age>>array[2].location>>
array[3].AdditionalNote;
}
int R(){
srand(time(0));
cout <<"\n"<< "Your code: "<< rand();
}
int gethelp(){
srand(time(0));
return rand()%(10-5+1)+5;
}
int main(){
string temp[size];
string tem;
Info Array [5];
string answer;
string repla;
cout<< " 911 What's your emergency? \n" ;
cout<< endl;
for(int i = 0; i<size ; i++){
cout<< services[i]<<"\t";}
cout<< endl;
cout<< endl;
cout << "Enter your choice as word all small, ex: fire.\n";
cout << "To repeate the menu in anoter order inter (other)\n";
cout << "To sort the menu alphabetaically inter (abc) \n";
Ask(search);
if (search == "other"){ // Shifting -right by 2
int NewIndex;
for (int i=0; i<size;i++)
{ NewIndex=i+2;
if(NewIndex >=size)
NewIndex=NewIndex % size;
temp [NewIndex]= services[i];
;}
cout<< "The new order:"<< endl;
for (int i =0; i<size; i++)
cout<< temp[i]<< "\t";
Ask(search);
}
if (search == "abc"){//Sorting Alphabetically
for (int x = 0; x < size; x++) {
for (int y = x+1; y < size; y++) {
if (services[x]>services [y]){
tem=services [x];
services[x]=services[y];
services[y]=tem;}}}
cout << "\nAlphabetical order of servisec :\n";
for (int x = 0; x < size; x++)
cout << services[x] << "\t";
cout << endl;
Ask(search);}
cout<<endl;
cout<<"___________________________________________________ \n";
cout<<endl;
get_data(Array,5);// Calling Function to get data fron user
cout<<"Okay " << Array[0].name << " calm down, we will send you help \n";
cout<<
"Your Name: "<<"\t"<< Array[0].name << "\n";
cout<<
"Your Age: "<<"\t"<< Array[1].age << "\n";
cout<<
"Your Location: "<<"\t"<< Array[2].location << "\n";
cout<<
"Additional Note: "<<"\t"<< Array[3].AdditionalNote << "\t";
cout<<"\n"<<" Please enter 1 if your info are right or 2 if you need to modify";
cin>> answer;
if (answer == "2"){
string Qrep;
string Qrepp;
string rep;
int repp;
int replaa;
cout<<"Do you want to replace? Enter Y or N"<< endl; .
i want to add to this c++ code a condition so that you can only chose.docx
1. i want to add to this c++ code a condition so that you can only chose from - robbery,
violation,medical, fire- if the user enterd something else the program should ask him to
again chose from this service only... plz don't change the code alot just add .
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <time.h>
using namespace std;
const int size = 5 ;
string services [size]= {"Robbery ", "Violation ", "Medical ","Fire "};//The menu
string search;
string Thesrevice;
struct Info {
string name;
int age;
2. string location;
string AdditionalNote;
};
void Ask(string &z){// Function for Searching in array
cout<< "n Your emergency?";
cout << endl;
cin>> z;
for (int i = 0 ; i< size ; i++){
if (services[i].find(z,0)!= string::npos){
cout<< "Your choice is "<< services[i]<<endl;
3. Thesrevice = services[i];
break;}
}}
void get_data(Info *array,int S){
cout<< "Enter Your name, age, location and any additional note"<<endl;
cin>> array[0].name>>array[1].age>>array[2].location>>
array[3].AdditionalNote;
}
int R(){
srand(time(0));
4. cout <<"n"<< "Your code: "<< rand();
}
int gethelp(){
srand(time(0));
return rand()%(10-5+1)+5;
}
int main(){
string temp[size];
string tem;
Info Array [5];
string answer;
string repla;
cout<< " 911 What's your emergency? n" ;
cout<< endl;
5. for(int i = 0; i<size ; i++){
cout<< services[i]<<"t";}
cout<< endl;
cout<< endl;
cout << "Enter your choice as word all small, ex: fire.n";
cout << "To repeate the menu in anoter order inter (other)n";
cout << "To sort the menu alphabetaically inter (abc) n";
Ask(search);
if (search == "other"){ // Shifting -right by 2
int NewIndex;
for (int i=0; i<size;i++)
7. if (search == "abc"){//Sorting Alphabetically
for (int x = 0; x < size; x++) {
for (int y = x+1; y < size; y++) {
if (services[x]>services [y]){
tem=services [x];
services[x]=services[y];
services[y]=tem;}}}
cout << "nAlphabetical order of servisec :n";
for (int x = 0; x < size; x++)
cout << services[x] << "t";
cout << endl;
8. Ask(search);}
cout<<endl;
cout<<"___________________________________________________ n";
cout<<endl;
get_data(Array,5);// Calling Function to get data fron user
cout<<"Okay " << Array[0].name << " calm down, we will send you help n";
cout<<
"Your Name: "<<"t"<< Array[0].name << "n";
cout<<
"Your Age: "<<"t"<< Array[1].age << "n";
cout<<
"Your Location: "<<"t"<< Array[2].location << "n";
cout<<
"Additional Note: "<<"t"<< Array[3].AdditionalNote << "t";
cout<<"n"<<" Please enter 1 if your info are right or 2 if you need to modify";
9. cin>> answer;
if (answer == "2"){
string Qrep;
string Qrepp;
string rep;
int repp;
int replaa;
cout<<"Do you want to replace? Enter Y or N"<< endl; //Adding value
cin>> Qrep;
if(Qrep == "Y"){
10. cout << "Is it your age? Enter Y or N"<< endl;
cin >> Qrepp;
if (Qrepp == "Y"){
cout<< "Enter your real age please!"<< endl;
cin>> repp; }