【发布时间】:2017-11-09 21:10:20
【问题描述】:
它是整个代码的一部分。当我尝试执行时,它会正常运行,直到“输入月份并收到付款”。但是,在此消息之后,我将哈希索引和值设置为“7 月 315.14”。突然,它打印“另一个查询(Y/N)?”在无限循环中。我的错误点在哪里?
unordered_map<string,float> monthly_payment;
char query;
string month;
cout << "Enter number of payments : ";
cin >> payNum;
cout <<"Enter month and payment received : " << endl;
for(int i=0; i<payNum; i++){
getline(cin, month,'\n');
cin >> payment;
monthly_payment.insert(pair<string, float>(month,payment));
}
cout << "Enter query month : ";
getline(cin, month, '\n');
cout << "The payment is " << monthly_payment[month]<<endl;
do{
cout << "Another query (Y/N)? ";
cin >> query;
if(query=='Y'){
cout << "Enter query month : ";
getline(cin, month, '\n');
cout << "The payment is " << monthly_payment[month]<<endl;
}
}while(query!='N');
【问题讨论】:
-
什么编程语言?
-
是C++......
-
如果您希望了解 C++ 的人查看问题,请将其添加为标签,否则他们可能看不到。