برنامه ای میخوام که بگه کی بهترین حدس زده - هفت خط کد انجمن پرسش و پاسخ برنامه نویسی

برنامه ای میخوام که بگه کی بهترین حدس زده

0 امتیاز

یه برنامه ای میخوام که یه عدد به صورت رندوم اعلام کنه بعد هرکس یه عدد بگه هر وقت عدد منفی یک گفته شد برنامه بگه چندمین نفر بهترین حدس و نزدیک ترین حدس اعلام کرده؟
خودم فقط تونستم نزدیک ترین عدد بگم نتونستم بگم چندومین نفر اعلام کرده

 

#include <iostream>

#include <iomanip>

#include <limits>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <windows.h>

#include <ctime>

#include <conio.h>

#include <stdio.h>

using namespace std;

int main ()

{int a=0,w=100,s,d,e,q,r,max1=0,max2=0,min1=0,min2=s;

srand(time(0));

s=rand()%(w-a+1)+a;


for(;;)

{cout<<"enter a number:\t";

cin>>d;

if(d>max1)

max1=d;

if(d<min1)

min1=d;

if(d<s&&d>min1&&d>max2)

max2=d;

if(d>=s&&d<=max1)

min2=d;


if(d==-1)

{

e=s-max2;

r=min2-s;

if(e>r)

cout<<"\n the closest guess= \t"<<min2<<"\n **the difference between conjectured numbe and the random number:** \t"<<r;

else if(e<r)

cout<<"\n the closest guess= \t"<<max2<<"\n ***the difference between conjectured numbe and the random number:*** \t"<<e;

else if(e==r)

cout<<"\n the closest guess= \t"<<max2<<"and \t"<<min2<<"\n the difference between conjectured numbe and the random number: \t"<<r;

    break;

   

   

return 0;

}}}

 

سوال شده فروردین 5, 1398  بوسیله ی Mohammad amin (امتیاز 9)   1 1
ویرایش شده فروردین 6, 1398 بوسیله ی مصطفی ساتکی

پاسخ شما

اسم شما برای نمایش (دلخواه):
از ایمیل شما فقط برای ارسال اطلاعات بالا استفاده میشود.
تایید نامه ضد اسپم:

برای جلوگیری از این تایید در آینده, لطفا وارد شده یا ثبت نام کنید.
...