الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعدة في برنامج guess a number

مغلق
بدأه a.m.k18 في 5 يناير 2007 · 5 رد · 771 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله و بركاته

أرجو المساعدة في هذا البرنامج هل تقترحون اضافة بعض الأوامر ليصبح أكثر متعة و دقة ؟؟؟ و هل نستطيع تبسيطه أكثر من ذلك؟؟

#include <iostream>

using namespace std;

#include <cstdlib>

using std::rand;

#include <ctime>

void guessGame();

bool isCorrect( int, int );

int main()

{

guessGame();

return 0;

}

void guessGame()

{

int answer;

int guess;

char response;

do {

answer = 1 + rand() % 1000;

cout << "I have a number between 1 and 1000.\n"

<< "Can you guess my number?\n"

<< "Please type your first guess." << endl << "? ";

cin >> guess;

while ( !isCorrect( guess, answer ) )

cin >> guess;

cout << "\nExcellent! You guessed the number!\n"

<< "Would you like to play again (y or n)? ";

cin >> response;

cout << endl;

} while ( response == 'y' );

}

bool isCorrect( int g, int a )

{

if ( g == a )

return true;

if ( g < a )

cout << "Too low. Try again.\n? ";

else

cout << "Too high. Try again.\n? ";

return false;

}

New_Text_Document__2_.txt

#2

أرجو المساعدة يا شباب !!!

#3

أرجو المساعدة يا شباب !!!!!!!!!

ضروووووووررررررررري!!!!!!11

#4

هذي نسخة ابسط من برنامج بواااااااايد :)

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;



int main()
{
	srand(time(0)); //Seed random number

	int theNumber = rand() % 100 + 1; //Generate random number between 1 & 100
	int trials = 0, guess = 0; //variable for user guess and variable "trials" to keep 
							   //track of how many guessings have been entered

	while(guess != theNumber)
	{
				cout << "Enter your guess: "; cin >> guess;
				++trials;

				if (guess > theNumber)
				{
						  cout << "High baby!" << endl << endl;
				}
				else if (guess < theNumber)
				{
					 cout << "Low baby!" << endl << endl;
				}
	}

	cout << "That's it! the number is: " << guess << ". You guessed it in " << trials << " trials" << endl;






   return 0;
}

اما عن الإظافات ، تقدر بعد ما تلعب ، انت تفكر برقم و الكمبيوتر يعطيك اجابته :) (تبادل ادوار)

تم تعديل هذه المشاركة بواسطة Ferrum في 7 يناير 2007 في 21:25

:::كوت بو 6:::

IDE : Microsoft Visual Studio 2005 Pro

#5

االله يجزيك الخير

شكرا لك على التبسيط

#6

هذي نسخة فيها اظافة الكمبيوتر يخمن رقم :)

#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <ctime>

using namespace std;



int main()
{
	srand(time(0)); //Seed random number

	int theNumber = rand() % 100 + 1; //Generate random number between 1 & 100
	int trials = 0, guess = 0; //variable for user guess and variable "trials" to keep 
							   //track of how many guessings have been entered

	while(guess != theNumber)
	{
				cout << "Enter your guess: "; cin >> guess;
				++trials;

				if (guess > theNumber)
				{
						  cout << "High baby!" << endl << endl;
				}
				else if (guess < theNumber)
				{
					 cout << "Low baby!" << endl << endl;
				}
	}

	cout << "That's it! the number is: " << guess << ". You guessed it in " << trials << " trials" << endl;

	cout << "Now it's my turn! You guess a number and I will tell it" << endl;

	bool correct = false;
	while(!correct)
	{
				   int compNumber = rand() % 100 + 1;
				   char yesNo = 'y';
				   cout << "You guess " << compNumber << " right? (y/n)" << endl;
				   cin >> yesNo;
				   if (yesNo == 'n')
				   {
							 compNumber = rand() % 100 + 1; //Update the computer guess
				   }
				   else
				   {
					   correct = true;
				   }
	}
	cout << "Aha! I found it finally! Nice to play with you human " << endl;




   getch();
   return 0;
}
:::كوت بو 6:::

IDE : Microsoft Visual Studio 2005 Pro

هذا الموضوع مغلق.

مواضيع مشابهة