Does anyone know C++?

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

  1. Haha if you must.

    // 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;
    \tfloat num1 = 0;
    \tfloat num2 = 0;
    \tfloat num3 = 0;
    \tfloat num4 = 0;
    \tfloat num5 = 0;
    \tfloat 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\t\telse
    \t\t\t{
    \t\t\t\tcout <<"You have entered an invalid number" << endl;
    \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) << setw(12) << (num1/times_rolled)*100 << "%" << endl;
    \t\tcout <<" 2 \t " << num2 << "\t " << fixed << setprecision(2) << setw(12) << (num2/times_rolled)*100 << "%" << endl;
    \t\tcout <<" 3 \t " << num3 << "\t " << fixed << setprecision(2) << setw(12) << (num3/times_rolled)*100 << "%" << endl;
    \t\tcout <<" 4 \t " << num4 << "\t " << fixed << setprecision(2) << setw(12) << (num4/times_rolled)*100 << "%" << endl;
    \t\tcout <<" 5 \t " << num5 << "\t " << fixed << setprecision(2) << setw(12) << (num5/times_rolled)*100 << "%" << endl;
    \t\tcout <<" 6 \t " << num6 << "\t " << fixed << setprecision(2) << setw(12) << (num6/times_rolled)*100 << "%" << endl;

    \t\t//system("PAUSE");
    \t\treturn 0;
    }
     
  2. very nice 8-]
     
  3. Haha lol thanks I'm so baked right now, do you program?
     
  4. yeah i used to a lot, i used to write codes for forum customization mainly HTML, CSS, some C++ and started to learn PERL but that shit was intense lol
     
  5. Oh good shit dude. I hate programming right now dude, I took an introduction class for java and aced it but spent half my time playing online poker during the lecture lol.
     
  6. lol its pretty cool once you get the hang of it but its also a pain in the ass to keep up with.
     
  7. i took ap java in high school, best fucking class i ever took, for real. the teacher was easily the nicest teacher at that school. there was no lecture or homework or anything. you just show up, sit at your computer, and work on a few projects from the book. usually these were easy as hell and i finished them in like 15 minutes when they weren't due for like 3 more days. then i'd just work on applets and fun shit for the rest of the time.

    a few of us also went to a competition at devry between a bunch of high schools. that was tons of fun although the other schools had special programs for programming and stuff so we didn't exactly do well but so what.
     
  8. yea im getting fucked in my programming class right now but its python
     
  9. I really want to lean C++ but every time I try to teach myself I get mad frustrated cause there is no one there to answer all my questions and I hate that. I still want to learn though
     
  10. #30 OG TEX7, Mar 25, 2012
    Last edited by a moderator: Mar 26, 2012
    Nice!!
     

Share This Page