Random question but, I've got a fairly simple homework assignment that I need help on. It's about making a dice roll prorgram though C++ language and making a multiplication times table chart. If anyone knows indepth about C++ hit me up, any help is much appreciated
Hm, different language but fairly similar. The program I need to make is basically asking the user to enter how many times they would like to roll the dice, and as a result, the program would output how many times the user rolled each number on the die, like they rolled the number 5 4 times and the percentage of each number rolled
Yeah I've tried but all I get are threads similar to this with all this programming gibberish I don't understand.
yeah reading people's code is hard without a lot of comments you just gotta realize that a lot of it is probably gunna be the same general idea even if it looks really fucked up(like people might use fprintf/fscanf instead of cin/cout but its the same shit) pretty much all you can do is google examples of dice roll programs and try to pick out what you can understand. If something is completely over your head, try googling key phrases to figure out what the hell is going on. edit: I remember using this site a lot.. http://www.cplusplus.com/doc/tutorial/
Alright well I tried making the program, if anyone here knows C++ then here's my code. // CSIS 135, Spring 2012, Homework#3 /*PSEUDOCODE: Ask user desired amount of times dice rolled Store data under variable time_roll Input random number generator for numbers 1-6 Calculate amount of die rolled for each number 1-6 Calculate percentage of die rolled for each number 1-6 Input result to user*/ #include <iostream> #include <cstdlib> #include <ctime> #include <iomanip> using namespace std; int main() { \tsrand ((unsigned int)time(0)); \tint times_rolled; \tint rolled; \tint num1 = 0; \tint num2 = 0; \tint num3 = 0; \tint num4 = 0; \tint num5 = 0; \tint num6 = 0; \tcout <<"How many times would you like to roll the dice?" << endl; \tcin >> times_rolled; \t \t\tfor (int i = 0; i < times_rolled; ++i) \t\t{ \t\t\trolled = rand() % 6 + 1; \t\t \t\t\tif (rolled = 1) \t\t\t{ \t\t\t\tnum1++; \t\t\t} \t\t\telse if (rolled = 2) \t\t\t{ \t\t\t\tnum2++; \t\t\t} \t\t\telse if (rolled = 3) \t\t\t{ \t\t\t\tnum3++; \t\t\t} \t\t\telse if (rolled = 4) \t\t\t{ \t\t\t\tnum4++; \t\t\t} \t\t\telse if (rolled = 5) \t\t\t{ \t\t\t\tnum5++; \t\t\t} \t\t\telse if (rolled = 6) \t\t\t{ \t\t\t\tnum6++; \t\t\t} \t\t} \t\tcout <<"#Rolled \t #Times \t %Times" << endl; \t\tcout <<"----- \t ------- \t -------" << endl; \t\tcout <<" 1 \t " << num1 << "\t " << fixed << setprecision(2) << (num1/times_rolled)*100 << "%" << endl; \t\tcout <<" 2 \t " << num2 << "\t " << fixed << setprecision(2) << (num2/times_rolled)*100 << "%" << endl; \t\tcout <<" 3 \t " << num3 << "\t " << fixed << setprecision(2) << (num3/times_rolled)*100 << "%" << endl; \t\tcout <<" 4 \t " << num4 << "\t " << fixed << setprecision(2) << (num4/times_rolled)*100 << "%" << endl; \t\tcout <<" 5 \t " << num5 << "\t " << fixed << setprecision(2) << (num5/times_rolled)*100 << "%" << endl; \t\tcout <<" 6 \t " << num6 << "\t " << fixed << setprecision(2) << (num6/times_rolled)*100 << "%" << endl; \t\tsystem("PAUSE"); \t\treturn 0; } It compiles fine but when I enter like, 5, it would only roll the first number 5 times and skip the rest.
Asking grasscity to help you program... lol. For the if statement use "==" not "=". "=" is for declaring a var or changing it's value. "==" is for logic.
Man I did this exact same thing in my grade 12 year, I also had pictures and images show up when you rolled, and a genie that appeared, asking you to predict the roll of the die.. ..I honestly don't remember, because the way our class worked is one person would figure it out, and from then on it would be passed around through the entire room.
DUH, can't believe I made this stupid mistake. Thank you EDIT: Now the program shows how many times I rolled the die but not the percentage:/
I would say use the built-in rand() function and then just use a switch to add on to 6 different integer variables and then at the end divide the individual counts by the total. I haven't used C++ in a long time so I'm not going to attempt to post source code but it should be relatively easy Things to put in the code: For loop (for number of times to roll the dice using cin) srand(time(NULL)); rand() % 6 + 1; cout the statements if you are outputing to CMD