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

guessing game

بدأه قلبي شموخي في 2 نوفمبر 2011 · 2 رد · 544 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

انا محتاجه اكتب كود c++

ل guessing game

اذا ممكن احد يشرح لي فكرة السؤال

Write C++ program where the program picks a random number between 1 and 100 and asks the user to guess the number.

If the user guess is incorrect, you have to tell him if her/his guess is less than or greater than the number the program picked.

If the user guessed incorrectly for five times, you have to print "You lose, try again"

If the user guess is correct, you have to print "You Win!!"

In the two cases (the user guessed correctly, or the user guessed incorrectly for five times) you have to ask the user if she/he wants to play again or not by typing (y,n)

y: for yes,

n: for no.

If the user chose not to play, you have to print the total number of loses/wins she/he has got.

−2
#2

upppppppppppppppppppppppppppppppp

#3

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

تفضل اخي

#include<iostream.h>
#include<stdlib.h>
#include<time.h>
void play();
int main()
{

cout<<"I have a Number between 1 and 100"<<endl<<"Can you guess my Number...>";
play();
return 0;
}
void play()
{
int numberToBeGuessed,UserGuess,counter=0;
srand(time(0));
numberToBeGuessed=1+rand()%100;
cout<<numberToBeGuessed<<endl;
for(int x=1;x<=100;x++)
{
cout<<"Enter your guess   ";
cin>>UserGuess;
if(UserGuess==numberToBeGuessed)
{
cout<<"CONGRATULATION"<<endl<<"You guessed the number"<<endl;
break;
}
else if(UserGuess>numberToBeGuessed)
cout<<"Lower!!!";
else if (UserGuess<numberToBeGuessed)
cout<<"Higher!!!";
else if (UserGuess==0)
break;

}
if(x<10)
cout<<"Either you know the secret or you got lucky! "<<endl;
else
if(x==10)
cout<<"Ahah! you know the secret!"<<endl;
else
if(x>10)
cout<<"You should be able to do better! "<<endl;




}

بالتوفيق ان شاء الله

لاتنسانا من صالح دعائك

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