Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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