Quote:Original post by Kazgoroth
Do please refrain from posting in all caps, it comes off as rather rude. GDKnight has attempted to help you; if you'd like more information feel free to ask, but people here give thier time for free to help you, so cut the attitude. Also, this is really a beginners topic, so I'm moving it to the appropriate forum.
Now, this sounds suspiciously like doing your homework for you, so I'm not going to just hand over sourcecode, but I will walk you through what needs to be done. If you attempt to code a solution yourself and post the code, I'm sure people will be happy to give you pointers as to how you can fix any problems.
As I understand it, you wish to create a program which simulates rolling a pair of dice a certain number of times (which will be specified by the user). Now, if we think about this it can be broken down in to a number of smaller tasks.
First, you basically want to perform the same task a (unknown) number of times; generate a pair of random numbers and display it. To me this sounds like an excellent opportunity to create and use a function (function tutorial) which you can then call as many times as you need to.
So, we take the code to generate a random number, and place it in a function. Have that function return the random number. Now you can call this function as often as you like, and get a different random number each time. To output two random numbers, simply output the results of the function twice - it will give you a different number each time. You can directly output the results of the function, you don't need to store it in a variable first (i.e. you can simply put the function call in place of a variable on your output line).
Now, you've got a function that outputs random numbers, and outputting the result twice will give you a pair of results. This will nicely cover rolling a pair of dice once. You now need to do this task a number of times, so ask the user to input this value (tutorial covering basic input/output), and store it in a variable.
Since you want to perform the same task a certain amount of times, a For Loop (tutorial covering for loops) perfectly suits your needs. You can use the variable you got from the user earlier to set how many times your loop is executed.
So, the steps you need to carry out are:
- Ask the user to input the number of rolls they want. Store this in a variable.
- Have a function which generates and returns a random number.
- Set up a for loop to execute the number of times specified by the user.
- Have an output function inside that loop which outputs a pair of random numbers.
Hope that helps. Have a go at it, and if you can't figure it out then post your code and we'll see if we can give you some tips to improve it. Now you be nice to the other posters from now on, they're trying to help you. [wink]
The tutorials listed in this post are from www.cprogramming.com, and the full set can be found here.
I honestly don't think the OP was copping an attitude.