ユーザーが負の数を入力するまで、ユーザーに好きなだけ整数を入力させようとしています。最初のステップは、ATOF関数を使用して文字列を数値に変換し(私が行った)、ユーザーが整数を入力できるようにすることでした(atof関数を正しく使用できるかどうかを確認するために、一度だけ行うことができます.
正しい方向性を教えてくれるヘルプ/ヒントをいただければ幸いです。
これまでの私のコードは次のとおりです。
#include <iostream>
#include <string>
int main() {
using namespace std;
char buffer[256];
char tempBuff[256] = {'\n'};
double result;
int count = 0;
cout << "Testing " << endl;
cout << "Enter Any integers: ";
cin.getline(buffer,256);
for(int i = 0; i < strlen(buffer); i++)
{
if(isdigit(buffer[i]))
{
tempBuff[count] = buffer[i];
count++;
}
}
if (atof(tempBuff) > 0) {
result = atof(tempBuff) / 2;
}
cout << endl << "The integer you put was: " << tempBuff
<< " And dividing the integers "<< result << endl;
cin.ignore();
return 0;
}