【发布时间】:2017-12-04 21:27:10
【问题描述】:
大家好,我正在创建一个简单的 c++ 程序,除了计算接收到的信息之外,还可以将用户输入写入文本文件。到目前为止,我正在尝试将美元兑换成日元,但由于某种原因,我遇到了一个障碍,我无法弄清楚是什么阻止了程序编译信息。
//Dollars to Yen Project
#include <cstring>
#include <climits>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
class A
{
private:
float dollars, yen;
public:
void store(float);
float convert();
};
void A::store(float dollars1)
{
dollars = dollars1;
}
float A::convert() //mutators used
{
yen = dollars*0.0089;
return yen;
}
int main()
{
float dollars;
float yen;
cout << "Welcome to Japan, you will need to convert Dollars into Yen to spend money here\n" << endl;
string b;
while (1)
{
cout << "Enter the amount in dollars to be converted\n";
cin >> b;
system("pause");
if (b.find_first_not_of("1234567890.-") != string::npos) //input check validity
{
cout << "invalid number:" << b << endl;
}
else
{
break;
}
}
float r = atof(b.c_str());
A a;
a.store(r);
float c = a.convert();
stringstream ss;
ss << c;
string s1 = ss.str();
ofstream prog;
prog.open("money.txt");
prog << "The required amount of Yen is " + s1;
prog.close();
return 0;
}
任何帮助将不胜感激。谢谢!!
【问题讨论】:
-
阻止程序计算的东西是什么意思?编译错误?运行时错误?结果无效?
-
请花一些时间到read about how to ask good questions。然后编辑您的问题以向我们提供更多详细信息,例如一些示例输入,以及该输入的预期和实际输出。我也建议你learn how to debug your programs。如果您有构建错误,请复制它们(作为文本,完整和完整)并将它们粘贴到问题中(无需修改)。
-
你的电脑里有一些 GHOST,这就是事实
标签: c++ type-conversion currency