یه برنامه ای میخوام که یه عدد به صورت رندوم اعلام کنه بعد هرکس یه عدد بگه هر وقت عدد منفی یک گفته شد برنامه بگه چندمین نفر بهترین حدس و نزدیک ترین حدس اعلام کرده؟
خودم فقط تونستم نزدیک ترین عدد بگم نتونستم بگم چندومین نفر اعلام کرده
#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;
}}}