I'm still new to CPP but I'm trying to make a project that asks some questions about a hotel visit and repeats the answers back, pretty simple. So far I have this for code:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int df;
int days;
string bed;
string bn;
cout << "Welcome to C++ Hotel, we have to ask you a few questions about your stay in order to give you the correct rate." << endl;
cout << "First, what floor would you like to stay on? (We currently have rooms available from floors 2 to 12)" << endl;
cin >> df;
while (df > 12 && 2 < df){
cout << "Sorry, but your answer is invalid, please enter a floor from 2 to 12." << endl;
cin >> df;
}
cout << "Okay, we will register your room on floor " << df << "." << endl;
cout << "Now, what type of bed will you be requesting during your visit? On floor " << df << " we currently have doubles, queens, or a suite." << endl;
cin >> bed;
while (bed != "d" && bed != "q" && bed != "s"){
cout << "Sorry, but your answer is invalid, please choose between a double, queen or suite by entering either d, q, or s respectively." << endl;
cin >> bed;
}
if (bed == "d"){
string bn = "double";
}
if (bed == "q"){
string bn = "queen";
}
if (bed == "s"){
string bn = "suite";
}
cout << "Okay, your room will be on floor " << df << " with a " << bn << " sized bed!" << endl;
}
I want the user to be able to input d, q or s for the double, queen or suite bed size option, but I also want to repeat what they have chosen at the end of the question, and it obviously sounds stupid if it says something along the lines of "you have chosen the d sized bed!"
So instead I made a few if statements that basically set a new string variable based on what the user inputs for the original bed variable. So if they put in a d for double, the bn variable is set to "double", then at the end the bn is called upon in the final cout.
However, the code seems to just skip over the 3 if statements completely, and at then end when the variable is called upon it is just blank, the code runs fine with no errors or warnings or anything, but I can't figure out why it just doesn't recognize the code, it seems okay to me?
Aucun commentaire:
Enregistrer un commentaire