I'm having so far a pretty fun time with C++ i'm learning new stuff everyday, and i'm finally learning how the rand() works.
I'm writing a supposedely ( ) simple program that takes the the user inputed data and rolls however many dice that user types in.
*EDIT* HAHA it works now, thanks to someones help. There is no problems with this code now so you guys can use it as an example
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main ()
{
srand(time(0));
int number_of_soldiers;
int number_of_casualties;
number_of_casualties = 0;
cout << "How many soldiers do you have?\n";
cin >> number_of_soldiers;
cout << "You roll ";
cout << number_of_soldiers;
cout << " dice.\n";
while( number_of_soldiers-- > 0 ){
if( rand()%6 + 1 == 1 ){ ++number_of_casualties; }
}
cout << " You destroyed ";
cout << number_of_casualties;
cout << " units.";
return 0;
}
Edited by Whipsmack, 17 June 2005 - 05:51 PM.