如何写出以下既输出(c++程式)(请用我提供既骨干)

来源:百度知道 编辑:UC知道 时间:2024/05/15 16:21:24
程式的骨干
#include <iostream>
#include <stdlib.h>

using namespace std;
int main()
{
int a = rand()% N +1; // a is a random integer between 1 to N
return 0;
}

我想要既输出:
I have 3 shells and 1 pea. Which shell is the pea under?
Pick a number from 1 to 3> 4

I said a number from 1 to 3 ! 4 is NOT from 1 to 3 ...
Please try again...

I have 3 shells and 1 pea. Which shell is the pea under?
Pick a number from 1 to 3> 2

You LOSE...
The pea is under shell number:3, you picked 2
Enter C to continue, Q to quit > c

I have 3 shells and 1 pea. Which shell is the pea under?
Pick a number from 1 to 3> 1

You WIN...
The pea is under shell numb

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int N = 10;

int main()
{
srand( time(0) );

cout << "Please enter the number of shells>";
cin >> N;

int a = rand()% N +1; // a is a random integer between 1 to N
int input = 0;
char conti = 'c';
int winCount = 0;
int loseCount = 0;
while ( 1 )
{
cout << endl;

cout << "I have " << N << " shells and 1 pea.Which shell is the pea under?" << endl;
cout << "Pick a number from 1 to " << N << ">";
cin >> input;
if ( input < 1 || input > N )
{
cout << "I said a number from 1 to " << N << " ! " << input << " is NOT from 1 to " <&l