-2
안녕하세요. 저는 수신 된 정보를 계산하는 것 외에도 텍스트 파일에 사용자 입력을 작성하는 간단한 C++ 프로그램을 만들고 있습니다. 지금까지 나는 달러를 엔화로 전환하려고 노력하고 있습니다. 그러나 어떤 이유로 나는 프로그램이 정보를 수집하는 것을 방해하고있는 것을 파악할 수없는 장애물에 있습니다.사용자 입력에 기반한 계산 (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;
}
어떤 도움을 주시면 감사하겠습니다. 감사!!
프로그램을 계산하지 못하게하는 것이 무엇을 의미합니까? 컴파일 오류? 런타임 에러? 잘못된 결과입니까? – Lasoloz
[좋은 질문을하는 방법에 대해 읽어보십시오.] (http://stackoverflow.com/help/how-to-ask)에 시간을 할애하십시오. 그런 다음 질문을 편집하여 몇 가지 예제 입력과 같은 자세한 정보와 해당 입력의 예상 및 실제 출력을 제공하십시오. 또한 [프로그램 디버깅 방법을 배우십시오] (https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)를 제안합니다. 빌드 오류가있는 경우 텍스트를 전체 텍스트로 복사하여 수정하지 않고 해당 질문에 붙여 넣으십시오. –
귀하의 컴퓨터에 앉아있는 몇 가지 귀신이 있으며 진실입니다. –