FizzBuzz程序。用戶輸入用逗號分隔的數字。該程序讀取輸入並讓計算機知道是否可以被3,5或兩者整除。當用戶輸入15,5,30時,程序將只輸出第一個數字15,並在那裏停止。我究竟做錯了什麼?將字符串轉換爲整數向量
void processVector(vector<int> intVector)
{
bool loop;
for (int i = 0; i < intVector.size(); i++)
{
loop = true;
}
}
int main()
{
cout << "Welcome to the FizzBuzz program!" << endl;
cout << "This program will check if the number you enter is divisable by
3, 5, or both." << endl;
cout << "Please enter an array of numbers separated by a comma like so,
5,10,15" << endl;
cin >> userArray;
vector<int> loadVector(string inputString);
istringstream iss(userArray);
vector <int> v;
int i;
while (iss >> i);
{
v.push_back(i);
if (iss.peek() == ',')
iss.ignore();
if (i % 15 == 0)
{
cout << "Number " << i << " - FizzBuzz!" << endl;
}
else if (i % 3 == 0)
{
cout << "Number " << i << " Fizz!" << endl;
}
else if (i % 5 == 0)
{
cout << "Number " << i << " Buzz!" << endl;
}
else
{
cout << "Number entered is not divisable by 3 or 5." << endl;
}
}
system("pause");
}
請編輯您的問題包含[MCVE] – Slava
中你做錯了的事情很肯定的:不包含頭文件,未申報'userArray'。當與一個空的身體循環。當你不需要它時調用'system()'。聲明'loadVector()',但從不調用它。定義'processVector()',但從不以任何方式使用它。 –
@ Ben Voigt,謝謝,本,我確實有頭文件,我沒有在文章中完整複製代碼。頭文件我已經是.... 的#include 「stdafx.h中」 的#include 的#include 的#include 的#include 的#include ...... 我會在休息。再次感謝您的幫助 –
Ang316