Thread: Re: [Dev-C++] Please help with program bugs, i tried, no luck.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: ropbert d b. <lon...@ju...> - 2001-01-18 19:49:11
|
Here is a better program. Still have no idea why random not in dev-c++
lib. Anybody got any clue??
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int roll(void); // protypes
int dice_1; // Declared globals
int dice_2;
int roll()
{
dice_1 = (random(6) + 1); // dev-c++ does not have random
function
dice_2 = (random(6) + 1); // that i can find . use bcc55 for
this
return dice_1; // anyone else have information on
random??
}
int main()
{
int through = 0;
randomize();
do
{
roll();
cout<<" the value rolled is : "<<(dice_1+dice_2)<<endl;
cout <<" the first die was : "<<dice_1<<endl; // changed to int
cout<<" the second die was: "<<dice_2<<endl;
cout<<"Enter 1 to quit " ;
cin>>through;
// system("pause"); // not needed now
}while(through != 1);
return 0; // screen in console
mode
}
On Thu, 18 Jan 2001 07:02:35 -0800 (PST) tayo odesanya <ta...@ya...>
writes:
> Intranet Compilers
> Compilation Results
>
> 1 #include <iostream.h>
> 2 #include <stdlib.h>
> 3
> 4 int dice_1;
> 5 int dice_2;
> 6 int roll()
> 7 {
> 8 randomize();
> 9 dice_1 = random(6) + 1;
> 10 dice_2 = random(6) + 1;
> 11 return dice_1;
> 12 return dice_2;
> 13 }
> 14 int die1()
> 15 {
> 16 return dice_1;
> 17 }
> 18 int dice_2()
> 19 {
> 20 return dice_2;
> 21 }
> 22 int main()
> 23 {
> 24 cout<<" the value rolled is : "<<roll()<<endl;
> 25 cout <<" the first die was : "<<die1()<<endl;
> 26 cout<<" the second die was:"<<die2()<<endl;
> 27 return 0;
> 28 }
>
> language: C and C++
> options: Display all warnings
> options: Include math library during linking
>
> prog.cpp: In function `int roll()':
> prog.cpp:8: implicit declaration of function `int
> randomize(...)'
> c:/djgpp/include/stdlib.h:121: too many arguments to
> function `long int random()'
> prog.cpp:9: at this point in file
> c:/djgpp/include/stdlib.h:121: too many arguments to
> function `long int random()'
> prog.cpp:10: at this point in file
> prog.cpp: In function `int dice_2()':
> prog.cpp:5: previous non-function declaration `int
> dice_2'
> prog.cpp:19: conflicts with function declaration
> `int dice_2()'
> prog.cpp: In function `int main()':
> prog.cpp:26: implicit declaration of function `int
> die2(...)'
>
> Errors Found!
>
> You need to correct the errors so that the program
> compiles. The compiler was executed remotely from
> MarketCache1.netcarrier.net/209.140.169.18 on
> Thursday, January 18, 101, 8:51.
>
>
>
> Send comments to:ole...@ie....
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> yahoo.com/
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: ropbert d b. <lon...@ju...> - 2001-01-18 19:49:11
|
Here is a program which will run. NOTE: Random not available in dev-c++
libray that I can find.
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int roll(void); // protypes
int dice_1; // Declared globals
int dice_2;
int roll()
{
dice_1 = 1;
dice_2 = 2;
// dice_1 = (random(6) + 1); // dev-c++ does not have random
function
// dice_2 = (random(6) + 1); // that i can find . use bcc55 for
this
return dice_1; // anyone else have information on
random??
// return dice_2; // only one return value allowed
}
//int die1() // don't need these functions because
//{ // dice declared global
// return dice_1;
//}
//int die2_2()
//{
// return dice_2;
//}
int main()
{
// randomize();
cout<<" the value rolled is : "<<roll()<<endl;
cout <<" the first die was : "<<dice_1<<endl; // changed to int
cout<<" the second die was: "<<dice_2<<endl;
system("pause"); // added pause so you
can see
return 0; // screen in console
mode
}
On Thu, 18 Jan 2001 07:02:35 -0800 (PST) tayo odesanya <ta...@ya...>
writes:
> Intranet Compilers
> Compilation Results
>
> 1 #include <iostream.h>
> 2 #include <stdlib.h>
> 3
> 4 int dice_1;
> 5 int dice_2;
> 6 int roll()
> 7 {
> 8 randomize();
> 9 dice_1 = random(6) + 1;
> 10 dice_2 = random(6) + 1;
> 11 return dice_1;
> 12 return dice_2;
> 13 }
> 14 int die1()
> 15 {
> 16 return dice_1;
> 17 }
> 18 int dice_2()
> 19 {
> 20 return dice_2;
> 21 }
> 22 int main()
> 23 {
> 24 cout<<" the value rolled is : "<<roll()<<endl;
> 25 cout <<" the first die was : "<<die1()<<endl;
> 26 cout<<" the second die was:"<<die2()<<endl;
> 27 return 0;
> 28 }
>
> language: C and C++
> options: Display all warnings
> options: Include math library during linking
>
> prog.cpp: In function `int roll()':
> prog.cpp:8: implicit declaration of function `int
> randomize(...)'
> c:/djgpp/include/stdlib.h:121: too many arguments to
> function `long int random()'
> prog.cpp:9: at this point in file
> c:/djgpp/include/stdlib.h:121: too many arguments to
> function `long int random()'
> prog.cpp:10: at this point in file
> prog.cpp: In function `int dice_2()':
> prog.cpp:5: previous non-function declaration `int
> dice_2'
> prog.cpp:19: conflicts with function declaration
> `int dice_2()'
> prog.cpp: In function `int main()':
> prog.cpp:26: implicit declaration of function `int
> die2(...)'
>
> Errors Found!
>
> You need to correct the errors so that the program
> compiles. The compiler was executed remotely from
> MarketCache1.netcarrier.net/209.140.169.18 on
> Thursday, January 18, 101, 8:51.
>
>
>
> Send comments to:ole...@ie....
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> yahoo.com/
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: tayo o. <ta...@ya...> - 2001-01-18 21:36:21
|
Thanks for helping me out.
I appreciate this.
Tayo.
--- ropbert d baugh <lon...@ju...> wrote:
> Here is a program which will run. NOTE: Random not
> available in dev-c++
> libray that I can find.
> #include <iostream.h>
> #include <stdlib.h>
> #include <time.h>
>
> int roll(void); // protypes
>
> int dice_1; // Declared globals
> int dice_2;
>
> int roll()
> {
>
> dice_1 = 1;
> dice_2 = 2;
> // dice_1 = (random(6) + 1); // dev-c++
> does not have random
> function
> // dice_2 = (random(6) + 1); // that i can
> find . use bcc55 for
> this
> return dice_1; // anyone else
> have information on
> random??
> // return dice_2; // only one return value
> allowed
> }
> //int die1() // don't need these functions
> because
> //{ // dice declared global
> // return dice_1;
> //}
> //int die2_2()
> //{
> // return dice_2;
> //}
> int main()
> {
> // randomize();
> cout<<" the value rolled is : "<<roll()<<endl;
> cout <<" the first die was : "<<dice_1<<endl;
> // changed to int
> cout<<" the second die was: "<<dice_2<<endl;
> system("pause");
> // added pause so you
> can see
> return 0;
> // screen in console
> mode
>
> }
> On Thu, 18 Jan 2001 07:02:35 -0800 (PST) tayo
> odesanya <ta...@ya...>
> writes:
> > Intranet Compilers
> > Compilation Results
> >
> > 1 #include <iostream.h>
> > 2 #include <stdlib.h>
> > 3
> > 4 int dice_1;
> > 5 int dice_2;
> > 6 int roll()
> > 7 {
> > 8 randomize();
> > 9 dice_1 = random(6) + 1;
> > 10 dice_2 = random(6) + 1;
> > 11 return dice_1;
> > 12 return dice_2;
> > 13 }
> > 14 int die1()
> > 15 {
> > 16 return dice_1;
> > 17 }
> > 18 int dice_2()
> > 19 {
> > 20 return dice_2;
> > 21 }
> > 22 int main()
> > 23 {
> > 24 cout<<" the value rolled is :
> "<<roll()<<endl;
> > 25 cout <<" the first die was :
> "<<die1()<<endl;
> > 26 cout<<" the second die was:"<<die2()<<endl;
> > 27 return 0;
> > 28 }
> >
> > language: C and C++
> > options: Display all warnings
> > options: Include math library during linking
> >
> > prog.cpp: In function `int roll()':
> > prog.cpp:8: implicit declaration of function
> `int
> > randomize(...)'
> > c:/djgpp/include/stdlib.h:121: too many
> arguments to
> > function `long int random()'
> > prog.cpp:9: at this point in file
> > c:/djgpp/include/stdlib.h:121: too many
> arguments to
> > function `long int random()'
> > prog.cpp:10: at this point in file
> > prog.cpp: In function `int dice_2()':
> > prog.cpp:5: previous non-function declaration
> `int
> > dice_2'
> > prog.cpp:19: conflicts with function declaration
> > `int dice_2()'
> > prog.cpp: In function `int main()':
> > prog.cpp:26: implicit declaration of function
> `int
> > die2(...)'
> >
> > Errors Found!
> >
> > You need to correct the errors so that the
> program
> > compiles. The compiler was executed remotely from
> > MarketCache1.netcarrier.net/209.140.169.18 on
> > Thursday, January 18, 101, 8:51.
> >
> >
> >
> > Send comments to:ole...@ie....
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Get email at your own domain with Yahoo! Mail.
> > yahoo.com/
> >
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> >
>
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
>
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
|
|
From: Ioannis V. <no...@ya...> - 2001-01-18 21:42:57
|
In <stdlib.h> there is rand() and srand(). Ioannis * Ioannis Vranos * Programming pages: http://members.nbci.com/noicys * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...]On Behalf Of > tayo odesanya > Sent: Thursday, January 18, 2001 11:36 PM > To: dev...@li... > Subject: Re: [Dev-C++] Please help with program bugs, i tried, no luck. > > > Thanks for helping me out. > I appreciate this. > Tayo. |
|
From: <em...@te...> - 2001-01-19 04:33:04
|
I have been told that it is somehow possible to convert integers to strings using #include <strstream> and #include <string> using std::strstream and std::string But I have not been able to figure out how. Does anyone have any comments, suggestions, or an idea of how to do it? ^^;; |
|
From: ropbert d b. <lon...@ju...> - 2001-01-19 01:03:47
|
Thanks to Ionnis... Here is the completed game. Enjoy!
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int roll(void); // protypes
int dice_1; // Declared globals
int dice_2;
int roll()
{
// srand(6);
do
{
dice_1 = (rand() + 1); // dev-c++ does not have random function
}while(dice_1 >7);
do
{
dice_2 = (rand() + 1); // that i can find . use bcc55 for this
}while(dice_2 >7);
return dice_1; // anyone else have information on
random??
}
int main()
{
int through = 0, point = 0;;
int lose =0, first = 1, win ;
do
{
win = 0;
roll();
cout<<" the value rolled is : "<<(dice_1+dice_2)<<endl;
cout <<" the first die was : "<<dice_1<<endl; // changed to int
cout<<" the second die was: "<<dice_2<<endl;
if(first == 1) point = (dice_1 + dice_2);
if(dice_1+dice_2 == 11 && first ==1)
{
lose =1;
cout<<endl<<"Sorry You Lose"<<endl;
through = 1;
}
if(dice_1+dice_2 == 7 && first == 0)
{
lose =1;
cout<<endl<<"Sorry You Lose"<<endl;
through = 1;
}
if(first == 0 && (dice_1+dice_2) == point || first == 1 && point ==7)
{
cout<<endl<<"HAY You WIN!!!"<< endl;
first = win = 1;
}
if(win != 1)first = 0;
cout<<"Enter 1 to quit " ;
cin>>through;
}while(through != 1 || lose ==0);
return 0; // screen in console
mode
}
On Thu, 18 Jan 2001 07:02:35 -0800 (PST) tayo odesanya <ta...@ya...>
writes:
> Intranet Compilers
> Compilation Results
>
> 1 #include <iostream.h>
> 2 #include <stdlib.h>
> 3
> 4 int dice_1;
> 5 int dice_2;
> 6 int roll()
> 7 {
> 8 randomize();
> 9 dice_1 = random(6) + 1;
> 10 dice_2 = random(6) + 1;
> 11 return dice_1;
> 12 return dice_2;
> 13 }
> 14 int die1()
> 15 {
> 16 return dice_1;
> 17 }
> 18 int dice_2()
> 19 {
> 20 return dice_2;
> 21 }
> 22 int main()
> 23 {
> 24 cout<<" the value rolled is : "<<roll()<<endl;
> 25 cout <<" the first die was : "<<die1()<<endl;
> 26 cout<<" the second die was:"<<die2()<<endl;
> 27 return 0;
> 28 }
>
> language: C and C++
> options: Display all warnings
> options: Include math library during linking
>
> prog.cpp: In function `int roll()':
> prog.cpp:8: implicit declaration of function `int
> randomize(...)'
> c:/djgpp/include/stdlib.h:121: too many arguments to
> function `long int random()'
> prog.cpp:9: at this point in file
> c:/djgpp/include/stdlib.h:121: too many arguments to
> function `long int random()'
> prog.cpp:10: at this point in file
> prog.cpp: In function `int dice_2()':
> prog.cpp:5: previous non-function declaration `int
> dice_2'
> prog.cpp:19: conflicts with function declaration
> `int dice_2()'
> prog.cpp: In function `int main()':
> prog.cpp:26: implicit declaration of function `int
> die2(...)'
>
> Errors Found!
>
> You need to correct the errors so that the program
> compiles. The compiler was executed remotely from
> MarketCache1.netcarrier.net/209.140.169.18 on
> Thursday, January 18, 101, 8:51.
>
>
>
> Send comments to:ole...@ie....
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> yahoo.com/
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Ioannis V. <no...@ya...> - 2001-01-19 11:21:09
|
My ANSI C++ suggestions:
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...]On Behalf Of
> ropbert d baugh
> Sent: Friday, January 19, 2001 3:02 AM
> To: dev...@li...
> Subject: Re: [Dev-C++] Please help with program bugs, i tried, no luck.
>
>
> Thanks to Ionnis... Here is the completed game. Enjoy!
> #include <iostream.h>
#include <iostream>
> #include <stdlib.h>
or #include <cstdlib> better
> #include <time.h>
#include <ctime>
>
> int roll(void); // protypes
>
> int dice_1; // Declared globals
> int dice_2;
Try to avoid the use of global variables.
>
> int roll()
> {
using std::srand;
using std::rand;
> // srand(6);
srand(time(0)); // If srand() is given a standard value, rand() produces the
same values
// every time the program is executed.
> do
> {
> dice_1 = (rand() + 1); // dev-c++ does not have random function
It has, the rand() of the standard library. rand() produces a value from 0
to RAND_MAX. Usually RAND_MAX equals to 32767 but if you want to be portable
use RAND_MAX. So, if you want to produce values from 0 to 2 (3 values) use:
int dice_1=rand()/(RAND_MAX/3);
> }while(dice_1 >7);
// Use the trick i told you above.
> do
> {
> dice_2 = (rand() + 1); // that i can find . use bcc55 for this
> }while(dice_2 >7);
// The same
> return dice_1; // anyone else have information on
> random??
> }
>
> int main()
> {
> int through = 0, point = 0;;
> int lose =0, first = 1, win ;
>
> do
> {
> win = 0;
> roll();
> cout<<" the value rolled is : "<<(dice_1+dice_2)<<endl;
> cout <<" the first die was : "<<dice_1<<endl; // changed to int
> cout<<" the second die was: "<<dice_2<<endl;
>
> if(first == 1) point = (dice_1 + dice_2);
> if(dice_1+dice_2 == 11 && first ==1)
> {
> lose =1;
> cout<<endl<<"Sorry You Lose"<<endl;
> through = 1;
> }
> if(dice_1+dice_2 == 7 && first == 0)
> {
> lose =1;
> cout<<endl<<"Sorry You Lose"<<endl;
> through = 1;
> }
> if(first == 0 && (dice_1+dice_2) == point || first == 1 && point ==7)
> {
> cout<<endl<<"HAY You WIN!!!"<< endl;
> first = win = 1;
> }
> if(win != 1)first = 0;
> cout<<"Enter 1 to quit " ;
> cin>>through;
> }while(through != 1 || lose ==0);
>
> return 0; // screen in console
> mode
I did not check the whole program, see my suggestions and fix it. :)
Keeep coding,
Ioannis
* Ioannis Vranos
* Programming pages: http://members.nbci.com/noicys
* Alternative URL: http://run.to/noicys
|