Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Dice rolling program


  • Please log in to reply

#1
Whipsmack

Whipsmack

    New Member

  • Member
  • Pip
  • 9 posts
Okay sorry to bug you guys again, However I think this post might be more worthy of a discussion ;)

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 ( :tazz: ) 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.

  • 0

Advertisements


#2
Whipsmack

Whipsmack

    New Member

  • Topic Starter
  • Member
  • Pip
  • 9 posts
*edit* nm

Edited by Whipsmack, 19 June 2005 - 03:32 AM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP