Привет, я студент, поэтому я хотел сказать, извините, если мое письмо утомительно, не стесняйтесь меня исправлять.Как присвоить значение enum двойной переменной, заданной пользователем? C++
У меня возникла следующая проблема. Я пытаюсь присвоить значение enum int другой двойной переменной, чтобы сделать одно умножение. , поэтому переменная costOfRoom должна принимать значение D или T или S, которые относятся к перечислению. (D = 200, T = 150, S = 110)
это должно быть сделано пользователем.
Но не могу найти какой-либо способ, я попытался сделать вторую переменную строкой, но ее снова не работает. это будет просто взять символы обычно в виде строки будет делать :(
также попытался cin >> type_Ofroom costofroom ;
, но я думаю, что это используется в Java ??
Искал форум также не какой-либо аналогичный ответ :(
программа прекрасно работает она не имеет каких-либо ошибок компиляции :)
Спасибо за ваше время
/* build a software system which will allow a hotel receptionist,
to enter in bookings for guests who come to the desk.
The system should display the room options as:
Room Price Code
---------------------------------------------------------------
Deluxe Room £200 D
Twin Room £150 T
Single £110 S
The receptionist should be prompted to enter in the room type and the number of
nights a guest wishes to stay for and then calculate the amount
they need to pay.
*/
// solution
#include <iostream>
using namespace std;
int main() {
// decleration of variables
double number_OfDays = 0, Totalcost = 0, costofroom = 0;
enum type_Ofroom { D = 200, T = 150, S = 150 };
cout << "enter the type of the room " << endl << endl;
//input of room type
cin >> costofroom; // **here is the problem** i am trying to give the
// values of the enum varaiable
// it should have D or T or S but i cant make it
cout << "enter the number of the days " << endl << endl;
//input of days
cin >> number_OfDays;
// calculation
Totalcost = costofroom * number_OfDays;
// result
cout << "the costumer has to pay " << Totalcost << " pounds" << endl << endl;
return 0;
}
Вы можете написать свой собственный оператор CIN, взятый отсюда: http://stackoverflow.com/a/10371706/5313831 – buart