我试图用C++制作一个银行程序,在那里你可以查看钱包里的金额,以及你的银行账户中的存款和取款金额.当我尝试运行它时,它让我输入,但是当我输入任何内容时,它会Money in Wallet: 20一次又一次地重复,直到我得到堆栈溢出,我认为这有点讽刺,在一个名为Stack Overflow的网站上发布.
到目前为止这是我的代码:
#include <iostream>
using namespace std;
float money= 20.00;
float account=100.00;
float amount;
bool cmd;
void wallet()
{
cout<<"Money in Wallet: "<<money<<endl;
}
void bank()
{
cout<<"Money in Bank: "<<account<<endl;
}
void deposit()
{
cout<<"How much do you want to deposit?: ";
cin>>amount;
if (money>=amount)
{
account = account+amount;
money = money-amount;
}
else
{
cout<<"You don't have enough money!\n";
}
}
void withdraw()
{
cout<<"How much do you want to withdraw?: "; …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个程序来询问他们的名字,然后说"你好,(他们的名字)!" 背部.到目前为止,这是我的代码,"getchar()"只是暂停,我可以看到输出.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout<<"What is your name?:";
cin>>name;
cout<<"Hello, "<<name<<"!";
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这要求我输入,我输入我的名字,然后应用程序关闭!我不知道为什么以及如何解决它!请帮忙!
编辑:找出如何解决它.完成的代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout<<"What is your name?: ";
cin>>name;
cout<<"Hello, "<<name<<"!\n";
system("PAUSE");
return 0;
}
Run Code Online (Sandbox Code Playgroud)