Does anyone know C++?

Discussion in 'General' started by Jitros067, Mar 24, 2012.

  1. 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:smoke:
  2. i know java
  3. 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
  4. that some biggo titty bras
  5. I think you mean D++ :D
  6. Shameful bump, need immediate help!
  7. google might be able to help
  8. Yeah I've tried but all I get are threads similar to this with all this programming gibberish I don't understand.
  9. I took a half year class on it last year but I can't say I know it in depth
  10. lol... so umm.. then what the hell are you asking for?
  11. well there's your problem.
  12. 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..
  13. 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\tfor (int i = 0; i < times_rolled; ++i)

    \t\t\trolled = rand() % 6 + 1;
    \t\t\tif (rolled = 1)
    \t\t\telse if (rolled = 2)
    \t\t\telse if (rolled = 3)
    \t\t\telse if (rolled = 4)
    \t\t\telse if (rolled = 5)
    \t\t\telse if (rolled = 6)

    \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\treturn 0;

    It compiles fine but when I enter like, 5, it would only roll the first number 5 times and skip the rest.
  14. 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.
  15. 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.
  16. #16 Jitros067, Mar 25, 2012
    Last edited by a moderator: Mar 25, 2012
    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:/
  17. 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 :p

    Things to put in the code:

    For loop (for number of times to roll the dice using cin)

    rand() % 6 + 1;

    cout the statements if you are outputing to CMD
  18. I prefer HTML...
  19. Figured it out, thanks a lot guys:)
  20. let's see the code! :D

Share This Page