私のプログラムは2つの乱数の和に答えるようにしています。答えが正しい場合は「良い」、正しくない場合は「やり直してください。しかし、私はプログラムが何度も何度も何度も質問し続けたいと思っています。私のプログラムはユーザーがそれに答えると終了します。プログラムなしで同じことを聞いているユーザーにはC++
私は出力が
How much is 19 plus 7 (-1 to End)?: 25
No - Please try again: 26
Very good!
How much is 9 plus 12 (-1 to End)?: 21
Very good!
How much is 71 plus 15 (-1 to End)?: 1
No - Please try again: 86
Very good!
How much is 17 plus 33 (-1 to End)?: -1
私のコードのようになりたい:あなたが欲しい
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int number1,number2, answer;
int x=0 ;
srand(time(NULL));
number1 = rand() % 100 + 1;
number2 = rand() % 100 + 1;
x=number1 + number2;
cout << "What is the " << number1 << " plus " << number2 << " ?" << endl;
cin >> answer;
if (answer!=x)
cout << "No,Please try again.";
else
cout << "Very good!";
cin.clear();
cin.ignore();
cin.get();
return 0;
}
の場所での使用にこれをされますループ。 –
['while'](https://www.tutorialspoint.com/cplusplus/cpp_while_loop.htm)ループが必要になります。 –