[英]C++ char not being written?
I'm working on a banking program, but I've come across a weird problem with 我正在从事银行计划,但遇到了一个奇怪的问题
cin>> task; cin >>任务;
It's supposed start up a switch. 应该启动一个开关。 but it keeps skipping the input and ends the program.
但它会不断跳过输入并结束程序。
I even have an example of this on hand, that code works, but this one doesn't I'm not sure what I'm doing wrong. 我什至手头有一个例子,该代码有效,但是我不确定我做错了什么。
#include<iostream>
#include<conio.h>
#include<string>
#include <ctype.h>
using namespace std;
int main()
{
string name = "";
int count;
char task;
double bal = 0;
int depo, withd;
cout << "Welcome to bank of the future! Please sign in" << endl;
cin >> name;
cout << "Enter your account number." << endl;
cin >> count;
cout << "Welcome back " << name << " What would you like to do?";
cout << "\n A. Deposit \n B. Withdraw \n C. Show balance \n D. Quit" << endl;
cin >> task;
//just to check if it's being skipped over or not.
cout << "egg " << endl;
switch (task)
{
case 'A':
cout << "Enter an amount to deposit" << endl;
cin >> depo;
cout << "Prevous balance: " << bal << endl;
bal = bal + depo;
cout << "New balance: " << bal << endl;
break;
case 'B':
cout << "Enter an amount to withdraw" << endl;
cin >> withd;
cout << "Prevous balance: " << bal << endl;
bal = bal - withd;
cout << "New balance: " << bal << endl;
break;
case 'C':
cout << "Your current balance is " << bal << "\n For account: " << name << "Acount number: " << count << endl;
break;
case 'D':
cout << "Goodbye forever" << endl;
break;
}
return 0;
}
I think it may have to do with the char being upper or lower case. 我认为这可能与char是大写还是小写有关。 In the switch you specify that task is uppercase.
在开关中,您指定任务为大写。 When I tried your code with uppercase letters it worked for me, but when I entered a lowercase letter it ended the program.
当我尝试使用大写字母的代码时,它对我有用,但是当我输入小写字母时,它结束了程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.