//- The "proper" syntax for including standard header files in C++ is
sans-
// the .h
#include <cstdlib>
#include <iostream>
#include <ctime> // Needed to seed the random number generator.
//- Function to roll a single die. Call this function once for each die
needed.
int rollDie( void )
{
// use the modulo to determine the value of the die roll.
return ( ::rand( ) % 6 ) + 1;
}
int main(int argc, char *argv[])
{
//- Seed the random number generator so we don't get the same
// result each time.
::srand( ::time( 0 ) );
// Declare and set the die values
int die_1 = rollDie( );
int die_2 = rollDie( );
// Output the die values
cout << "You rolled a " << die_1 + die_2 << endl;
cout << " The first die is: " << die_1;
cout << " The second die is: " << die_2;
return 0;
}
tayo odesanya wrote:
> 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.
> http://personal.mail.yahoo.com/
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|