[英]C++ char not being written?
我正在從事銀行計划,但遇到了一個奇怪的問題
cin >>任務;
應該啟動一個開關。 但它會不斷跳過輸入並結束程序。
我什至手頭有一個例子,該代碼有效,但是我不確定我做錯了什么。
#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;
}
我認為這可能與char是大寫還是小寫有關。 在開關中,您指定任務為大寫。 當我嘗試使用大寫字母的代碼時,它對我有用,但是當我輸入小寫字母時,它結束了程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.