Hello guys again!
I am a C++ beginner and I am working on another project.. It's called Dice Lab with Loops..
unforunately I don't even know how to start the program....
Don't blame me for not pay attention in the class.. Seriously, my teacher just ask us to do the sample programs in the textbook and prepare for the finals...
Everytime I ask him question... he has to open the textbook to find the answer..
I've been searching for dice roll in the google but I can't really understand the codes..
I just want to ask how to roll two dice in a really simple way?
Or use the loops? For loops or while loops?
Does there have any function for it or----?
thanks alot....
---------------------------------------------This is the direction..!
Write a program that will roll two dice (each dice is from 1 to 6) and then total them together. The user should be able to input how many times they would like to have the dice rolled. Your program should output the rolls and once the rolls are done, it should output how many of each number had been rolled.
Example output
How many rolls would you like? 10
D1: 3 D2:6 Total: 9
D1: 4 D2:2 Total: 6
D1: 3 D2:1 Total: 4
D1: 5 D2:2 Total: 7
D1: 1 D2:1 Total: 2
D1: 2 D2:6 Total: 8
D1: 4 D2:4 Total: 8
D1: 6 D2:4 Total: 10
D1: 3 D2:4 Total: 7
D1: 5 D2:2 Total: 7
Dice Roll Totals
2=1
3=0
4=1
5=0
6=1
7=3
8=2
9=1
10=1
11=0
12=0
---------------------------------------------------------
4 6050 RedSon 5,000
Recognized Expert Expert
Hello guys again!
I am a C++ beginner and I am working on another project.. It's called Dice Lab with Loops..
unforunately I don't even know how to start the program....
Don't blame me for not pay attention in the class.. Seriously, my teacher just ask us to do the sample programs in the textbook and prepare for the finals...
Everytime I ask him question... he has to open the textbook to find the answer..
I've been searching for dice roll in the google but I can't really understand the codes..
I just want to ask how to roll two dice in a really simple way?
Or use the loops? For loops or while loops?
Does there have any function for it or----?
thanks alot....
---------------------------------------------This is the direction..!
Write a program that will roll two dice (each dice is from 1 to 6) and then total them together. The user should be able to input how many times they would like to have the dice rolled. Your program should output the rolls and once the rolls are done, it should output how many of each number had been rolled.
Example output
How many rolls would you like? 10
D1: 3 D2:6 Total: 9
D1: 4 D2:2 Total: 6
D1: 3 D2:1 Total: 4
D1: 5 D2:2 Total: 7
D1: 1 D2:1 Total: 2
D1: 2 D2:6 Total: 8
D1: 4 D2:4 Total: 8
D1: 6 D2:4 Total: 10
D1: 3 D2:4 Total: 7
D1: 5 D2:2 Total: 7
Dice Roll Totals
2=1
3=0
4=1
5=0
6=1
7=3
8=2
9=1
10=1
11=0
12=0
---------------------------------------------------------
You might want to try looking up srand(...) and rand(...) those things will probably be the biggest help to you.
First break down the logic of the program in regular words (don't worry about code). What steps would you do (in real life) to get the results that you wanted. Then after you have figured out the process convert that over into code. As far as determining the random part (the rolling of the dice) use Red Son's advice and look up srand and rand. If you still have problems with it post back up your questions and show us what you have tried.
hi
sorry for posting solution code, never again.
A good way to solve your problem would be to use rand() from stdlib.h and try to get a number between 1 and 6.
this could be done by producing a real number between 0 and 1 and keep for examble , from the real number 0.678284584... the 0.6 and multiply it by 10 and do that until you get a number between 1 - 6
RedSon 5,000
Recognized Expert Expert
hi,
read this peace of code i think will help you:
this function creates a random int number between [low....high] in your case put low = 1 and high = 6 and it make use of rand() from stdlib.h, so deleted
this function is taken from a library made by Eric S. Roberts who wrote the book
"The Art and Science of C" ISBN 960-209-791-4.
First off, we do not give code solutions to homework problems. Second, we do not post copyrighted code. This is your first last and only warning about this. Please read the posting guidelines so you will understand what is acceptable and what is not.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Richard B. Kreckel |
last post by:
Hi!
I was recently asked what book to recommend for a beginner in C++. I
am convinced that you needn't study C in depth before learning C++
(though it helps), but cannot find any beginner's book which isn't
aimed at people coming from C/Pascal/Java/Delpi/whatever...
However, there seem to be plenty such books for all those other
languages. Is there really no literature for people trying to learn
programming by starting with C++? ...
|
by: Grrrbau |
last post by:
I'm a beginner.
I'm looking for a good C++ book.
Someone told me about Lafore's "Object-Oriented Programming in C++".
What do you think?
Grrrbau
|
by: Rensjuh |
last post by:
Hello, does someone have / know a good C++ tutorial for beginnners? I would prefer Dutch, but English is also fine.
Hoi, heeft / kent iemand nog een goede C++ tutorial voor beginners? Het liefste in Nederlands, maar Engels is ook goed.
Thnx,
Rensjuh
|
by: MHoffman |
last post by:
I am just learning to program, and hoping someone can help
me with the following:
for a simple calculator, a string is entered into a text
box ... how do I prevent the user from entering a text
instead of a number, or give an error message?
Also, how can I make the program verify there are two
valid entries in txtBox1 and txtBox2 to then ENABLE the
button operators (ie +, -, /, *).
|
by: mitchellpal |
last post by:
Hi guys, am learning c as a beginner language and am finding it rough
especially with pointers and data files. What do you think, am i being
too pessimistic or thats how it happens for a beginner? Are there
better languages than c for a beginner? For instance visual basic or i
should just keep the confidence of improving?
| |
by: weight gain 2000 |
last post by:
Hello all!
I'm looking for a very good book for an absolute beginner on
VB.net or VB 2005 with emphasis on databases. What would you
reccommend?
Thanks!
|
by: macca |
last post by:
Hi, I'm looking for a good book on PHP design patterns for a OOP
beginner - Reccommendations please?
Thanks
Paul
|
by: Roman Zeilinger |
last post by:
Hi
I have a beginner question concerning fscanf.
First I had a text file which just contained some
hex numbers:
0C100012
0C100012
....
|
by: hamza612 |
last post by:
I want to start learning how to program. But I dont know where to
start. From what I've heard so far c++ is not a good lang. to learn
as a beginner because its very complicated compared to others like
python, ruby etc.
I would like to know if there is a prerequisite to learning any
computer language, is there something I have to learn before learning
any computer language, like a basic or core?
|
by: ddg_linux |
last post by:
I have been reading about and doing a lot of php code examples from
books but now I find myself wanting to do something practical with
some of the skills that I have learned.
I am a beginner php programmer and looking for a starting point in
regards to practical projects to work on.
What are some projects that beginner programmers usually start with?
Please list a few that would be good for a beginner PHP programmer to
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |