อยากถามคนที่เคยเรียน program c++ หรือผู้รู้ก็ได้ค่ะ
ว่าข้างล่างนี่มันแปลว่าอะไร ทีล่ะบรรทัดนะค่ะ
#include <iostream>
#include <ctime>
#include <cstdlib>
#define MAX_GUESS 7
#define MAX_RANGE 1000
using namespace std;
bool inRange(int g);
void playGame();
int main()
{
char answer;
cout << "Welcome to the game GuessNumber" << endl;
cout << "You must guest a number between 1 and "
<< MAX_RANGE << "\n"
<< "You can win if you can guess the number within "
<< MAX_GUESS << " times." << endl;
do
{ playGame();
cout << "\n Do you want to play again?[y/n]:";
cin >> answer;
} while (answer == 'y');
return 0;
}
bool inRange(int g)
{
if (g>=1 && g<=MAX_RANGE) return true;
return false;
}
void playGame()
{
srand(time(NULL));
int x = rand()%MAX_RANGE + 1;
int g;
// to store all guess numbers
int guesses [10]= {};
for (int i=1; i<=MAX_GUESS; i++)
{
cout << "Guess " << i << " : ";
cin >> g;
// Storing a guess number
guesses= g;
if (inRange(g)) {
if (g==x) {
cout << "*** Hurrah! You are correct" << endl;
return ;
}
else if (g<x) {
cout << "It's too little" << endl;
}
else {
cout << "It's too much" << endl;
}
} else {
cout << g << " is not in the valid range of 1-"
<< MAX_RANGE << endl;
}
//Showing all previous numbers
cout << "Previous guesses are";
for (int j=1; j<=i; j++)
{ cout << guesses[j] << " ";
}
cout << endl;
}
cout << "*** Sorry! you lose!" << endl;
cout << "... The number is " << x << endl;
return ;
}
********ขอบคุณทุกคนที่เข้ามาอ่านและช่วยเหลือนะค่ะ ^^*******
ขอความช่วยเหลือแปลภาษา C++
ว่าข้างล่างนี่มันแปลว่าอะไร ทีล่ะบรรทัดนะค่ะ
#include <iostream>
#include <ctime>
#include <cstdlib>
#define MAX_GUESS 7
#define MAX_RANGE 1000
using namespace std;
bool inRange(int g);
void playGame();
int main()
{
char answer;
cout << "Welcome to the game GuessNumber" << endl;
cout << "You must guest a number between 1 and "
<< MAX_RANGE << "\n"
<< "You can win if you can guess the number within "
<< MAX_GUESS << " times." << endl;
do
{ playGame();
cout << "\n Do you want to play again?[y/n]:";
cin >> answer;
} while (answer == 'y');
return 0;
}
bool inRange(int g)
{
if (g>=1 && g<=MAX_RANGE) return true;
return false;
}
void playGame()
{
srand(time(NULL));
int x = rand()%MAX_RANGE + 1;
int g;
// to store all guess numbers
int guesses [10]= {};
for (int i=1; i<=MAX_GUESS; i++)
{
cout << "Guess " << i << " : ";
cin >> g;
// Storing a guess number
guesses= g;
if (inRange(g)) {
if (g==x) {
cout << "*** Hurrah! You are correct" << endl;
return ;
}
else if (g<x) {
cout << "It's too little" << endl;
}
else {
cout << "It's too much" << endl;
}
} else {
cout << g << " is not in the valid range of 1-"
<< MAX_RANGE << endl;
}
//Showing all previous numbers
cout << "Previous guesses are";
for (int j=1; j<=i; j++)
{ cout << guesses[j] << " ";
}
cout << endl;
}
cout << "*** Sorry! you lose!" << endl;
cout << "... The number is " << x << endl;
return ;
}
********ขอบคุณทุกคนที่เข้ามาอ่านและช่วยเหลือนะค่ะ ^^*******