d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Roll Program Help
12Next
Add Reply New Topic New Poll
Member
Posts: 4,292
Joined: Jan 7 2011
Gold: 461.00
Jan 7 2015 02:49pm
Hello, could somebody help me with roll program? Or write it for me? Info via pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 7 2015 03:39pm
post what you have and what you need help with.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 7 2015 03:53pm
Quote
I have to write a roll program which rolls numbers from 0 to 10, and if he roll the same number twice, he will end up showing message "THE END. I have tried # times" where # is the number of tries.


and what do you have and what do you need help with?
Member
Posts: 4,292
Joined: Jan 7 2011
Gold: 461.00
Jan 7 2015 04:04pm
Quote (carteblanche @ Jan 7 2015 10:53pm)
and what do you have and what do you need help with?


actually i could write a program which rolls from 1 to 9. I dont have any idea on how to do the same to make it roll until it gets 2 the same numbers with that finish message.

I can put a code with what i've done but its in other language than english so you wont understand some of the lines.

This post was edited by Devusss on Jan 7 2015 04:27pm
Retired Moderator
Posts: 18,570
Joined: Feb 27 2004
Gold: 11,858.00
Trader: Trusted
Jan 7 2015 05:09pm
Quote (Devusss @ Jan 7 2015 04:04pm)
actually i could write a program which rolls from 1 to 9. I dont have any idea on how to do the same to make it roll until it gets 2 the same numbers with that finish message.

I can put a code with what i've done but its in other language than english so you wont understand some of the lines.


Post your code in CODE brackets.

What exactly is not in english? The variable names? If so, that's not a big deal.
Member
Posts: 4,292
Joined: Jan 7 2011
Gold: 461.00
Jan 7 2015 05:56pm
Code
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int liczba,licz,n, proba=0;

int liczba_losowa(float l);




int main()

{

{
cout << "losuje pierwsza liczbe z zakresu 0...10" << endl;
srand(time(NULL));
liczba=rand()%11;
cout << liczba <<endl;

cout << "losuje druga liczbe z zakresu 0...10" << endl;
licz=rand()%11;
cout << licz <<endl;

while(liczba!=licz)
{
proba++;
if (licz==liczba)
cout <<"koniec, probowalem "<<proba<<" razy" << endl;
else if (licz>liczba)
cout << "probuje ponownie"<< endl;
else if (licz<liczba)
cout <<"probuje ponownie" << endl;

}
}


return 0;

}


what to put into while() ?? some kind of another function 'n' thats licz-liczba=0?
Like that it is atm it shows endless message of "trying again"

This post was edited by Devusss on Jan 7 2015 05:58pm
Member
Posts: 62,215
Joined: Jun 3 2007
Gold: 9,039.20
Jan 7 2015 06:03pm
psudo code:
Code

number = 0
tries = 0

loop do
random = Random.rand(10)
tries += 1
if number == random
puts "Sequential numbers found in #{tries} tries"
break
end
number = random
end


output:
Code

ruby Devusss.rb
Process started >>>
Sequential numbers found in 7 tries
<<< Process finished. (Exit code 0)
================ READY ================
ruby Devusss.rb
Process started >>>
Sequential numbers found in 1 tries
<<< Process finished. (Exit code 0)
================ READY ================
ruby Devusss.rb
Process started >>>
Sequential numbers found in 8 tries
<<< Process finished. (Exit code 0)
================ READY ================
ruby Devusss.rb
Process started >>>
Sequential numbers found in 11 tries
<<< Process finished. (Exit code 0)
================ READY ================
Member
Posts: 4,292
Joined: Jan 7 2011
Gold: 461.00
Jan 7 2015 06:29pm
I dont really get how to use that code to edit my c++ code.

Code
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int liczba,licz,n=1, proba=0;

int liczba_losowa(float l);




int main()

{

{
proba++;
cout << "losuje pierwsza liczbe z zakresu 0...10" << endl;
srand(time(NULL));
liczba=rand()%11;
cout << liczba <<endl;

cout << "losuje druga liczbe z zakresu 0...10" << endl;
licz=rand()%11;
cout << licz <<endl;

do



{
if (licz==liczba)
cout <<"koniec, probowalem "<<proba<<" razy" << endl;
else if (n>1)
cout << "probuje ponownie" << endl;
else if (1>n)
cout << "probuje ponownie" << endl;
}

while(n=licz/liczba);

}



return 0;
}


Still doesnt work

This post was edited by Devusss on Jan 7 2015 06:36pm
Member
Posts: 4,292
Joined: Jan 7 2011
Gold: 461.00
Jan 7 2015 07:11pm
Delete thread plz
Member
Posts: 9,099
Joined: Nov 23 2002
Gold: 2,911.26
Jan 8 2015 07:04am
Code
oldRand=18888
while 1
randNum=rand(int, 1, 9)
if oldRand==randNum
break
end
oldRand=randNum
disp(randNum)
end
disp(randNum) and disp(oldRand) are the same


This post was edited by TheStealthTarget on Jan 8 2015 07:05am
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll