Heres what I have to do I have to write a program that asks theuser what hotel s
ID: 3609266 • Letter: H
Question
Heres what I have to do I have to write a program that asks theuser what hotel suite they want which would then show theirselection along with the pricethis is the code:
#include<iostream>
#include<string>
using namespace std;
int main()
{
const int SZ = 5;
const char QUIT = 'z';
char answers[SZ] = {'a', 'b', 'c', 'd', 'e'};
double price[SZ] = {149.95, 215.66, 239.77, 308.11,500.99};
string suite[] = {"Alyse", "Botanical". "Crimson",
"Darlton", "Edwardian"};
char selection;
int x;
int flag;
cout << "Enter your choice of our hotel suites"<< endl;
for(x = 0; x < SZ; ++x){
cout << answers[x] << "for the " << suite[x] << " suite" << endl;
cout << "Enter " << QUIT << " toquit ";
cin << selection;}
while(selection != QUIT)
{
flag = 0;
for(x = 0; x < SZ ; ++x)
if(selection == answers[x])
{
cout <<"Price per night for the " << suite[x] <<
" is$" << price[x] << endl;
flag = 0;
}
if(flag = 0)
cout << "Sorry - invalid selection"<< endl;
cout << "Enter next selectionor " << QUIT << " to quit ";
cin >> selection
}
return 0;
}
notice the flag variable which would issue a message if a wronghotel has been picked
i think the errors are pure syntax errors but I cannot find themand as I changed the code I either crashed it or got a never endingloop
please help and if possible keep the code as it is or close toit
Explanation / Answer
here you go man, you had a few stupid syntax errors such as a .instead of a comma when you declared suite, also when you iteratethrough your for loops you need to go to SZ-1 not SZ because anarrays elements are 0-SZ-1. array[1] is actually the second elementof the array. You also has a few errors such as some miss matched{} and you needed to add 1 to flag each time through the for loopand if flag == 4you broadcast that the choice was invalid. One final error was that you uses if (flag = 0), which should be ==not =, as = assigns a value to something while == checks if theyare the same. and 0 is supposed to be 4 as a mentioned earlier.Other than that it was a solid program and it works fine for me. Ifyou have any questions feel free to ask. #include #include using namespace std; int main() { const int SZ = 5; const char QUIT = 'z'; char answers[SZ] = {'a', 'b', 'c', 'd', 'e'}; double price[SZ] = {149.95, 215.66, 239.77, 308.11,500.99}; string suite[SZ] = {"Alyse", "Botanical", "Crimson","Darlton", "Edwardian"}; char selection; int x; int flag; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.