このプログラムは、正の数を要求するクラス用に作成し、その数に基づいて計算が実行されます。先週、スタック関係者から多大な支援を受けましたが、教授からコードを書き直してコードを簡素化するように依頼されました。私はそれをしましたが、今は数学が正しく出ていません。デバッガーを実行しましたが、渡された値が間違っている場所がわかりません。また、すべての数字が「if (number > 0)」テストに失敗しています。
ビルドが成功したというメッセージが表示されても、コンパイル エラーでしょうか?
前もって感謝します!
これがコードです。
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include <cstdlib>
using namespace std;
int main ()
{
system ("color F0");
int number, countIf = 0, countWhile = 0, countDo = -1, h = 0, i = 0, x = 0, y = 0;
char repeat = 'y';
do {
cout << "Please enter a positive integer or zero to quit: ";
cin >> number;
x = number, y = number;
cin.ignore();
if (number < 0)
cout << "Error: The integer entered was either not positive or a zero.\n" << endl;
else if (number > 0)
{
if (number%2 == 0 && number%5 == 0)
for (y%5; countIf <= y; countIf +=5)
{
i = y / 10;
i += countIf;
cout << countIf << " ";
}
else if
(countWhile < x && number%2 == 0)
{
countWhile += 2;
cout << countWhile << " ";
}
else
{
countDo +=2;
cout << countDo << " ";
}
}
cout << "\n\nDo you wish to continue? (Y or N): ";
cin >> repeat;
}
while (number != 0 && repeat == 'y' || repeat == 'Y');
//cout << "\nThanks for playing!" << endl;
system ("pause");
return 0;
}
出力は次のようになります。
私が得ているものは次のとおりです。