Thread: C++ Final!

Page 1 of 3
1
2
3
LastLast
  1. #1

    C++ Final!

    So I just finished my C++ final for my introductory programming class and thought I might post it here so that I could get maybe a little feedback on couple things I could improve before I turn it in. I really don't want to see a bunch of I'm not clicking the link or suspicious link is suspicious replies, so if you don't want to click it... don't.

    The link to the game is http://www.sendspace.com/file/vs7vrs .

    Also like I said this is a very simple game so don't expect your mind to be blown or anything.
    Any constructive comments would be greatly appreciated.

    EDIT: Here is the source code file http://www.sendspace.com/file/53q38h . (We had to use a variety of techniques in the file so some of it prolly looks stupid for me to have done it that way i.e. the switch statements, also i know it is messy :P)
    Last edited by Erradic; 2011-04-19 at 11:40 PM.

  2. #2
    Bloodsail Admiral Dassen's Avatar
    10+ Year Old Account
    Join Date
    Jan 2010
    Location
    Sweden
    Posts
    1,087
    I haven't looked at it yet but my mouth started watering when I read "C++".
    Any chance of a source code? Pretty, pretty please.
    "After dealing with about 10 000 patients over the last 15 years, I would say that over 200 different medical conditions respond favorably to cannabis."
    - The late Dr. Tod Mikuriya, MD, interview in The Union: The business behind getting high
    Former national administrator of the U.S. Government's marijuana research programs
    http://yourlogicalfallacyis.com/home

  3. #3
    I will follow this thread, but im not clicking on it cuz im too cautious.

  4. #4
    Bloodsail Admiral Dassen's Avatar
    10+ Year Old Account
    Join Date
    Jan 2010
    Location
    Sweden
    Posts
    1,087
    Quote Originally Posted by Nexus2089 View Post
    I will follow this thread, but im not clicking on it cuz im too cautious.
    Can confirm safety of link & downloaded file. It's a text-based boardgame.
    Download Avast! Antivirus and you can browse/download anything you want. It'll scan it real-time and if it's malicious it'll get aborted/removed.
    (the download link is 'Download link: final.exe" at the bottom, not one of the flashy sparkly ads)
    Last edited by Dassen; 2011-04-19 at 11:21 PM.
    "After dealing with about 10 000 patients over the last 15 years, I would say that over 200 different medical conditions respond favorably to cannabis."
    - The late Dr. Tod Mikuriya, MD, interview in The Union: The business behind getting high
    Former national administrator of the U.S. Government's marijuana research programs
    http://yourlogicalfallacyis.com/home

  5. #5
    The instructions working would be a good start!
    Although REALLY not necessary, you could have a bit of text-art whenever you land on a tile. For example
    ------
    |<--2|
    ------
    Nothing fancy, and it looks better when on CMD.
    Quote Originally Posted by Moaradin
    What do you do when you see a Xbox 360? You turn 360.2 durr

  6. #6
    Quote Originally Posted by kriissii1 View Post
    The instructions working would be a good start!
    Although REALLY not necessary, you could have a bit of text-art whenever you land on a tile. For example
    ------
    |<--2|
    ------
    Nothing fancy, and it looks better when on CMD.
    lol good suggestions i complete forgot about the instructions and meant to add them after i finished the game and will definitely try to work on some word art stuff for the title!

  7. #7
    Add a boolean check on all your cins (there are more effecient ways to preform the same thing but this one is easiest to understand)

    if (!(cin >> variable name))
    {
    cin.clear();
    cin.ignore(1000,'\n');
    cout << "Please enter a valid selection";
    }

    Or something similar, your program is easily crashed by entering any char value into your double or int cins. (For example enter a - and watch it spool).

    I'll post some more things as I get more time to look at this but for the time being I can confirm the dl is safe.

  8. #8
    Entered a hyphen instead of a 1 to roll, the program went into an infinite loop.

    fix

  9. #9
    Quote Originally Posted by Zulandia View Post
    Add a boolean check on all your cins (there are more effecient ways to preform the same thing but this one is easiest to understand)

    if (!(cin >> variable name))
    {
    cin.clear();
    cin.ignore(1000,'\n');
    cout << "Please enter a valid selection";
    }

    Or something similar, your program is easily crashed by entering any char value into your double or int cins. (For example enter a - and watch it spool).

    I'll post some more things as I get more time to look at this but for the time being I can confirm the dl is safe.
    I did find this problem but i was unsure about how to fix it... i'll try to fix this. thanks!

  10. #10

  11. #11
    cin >> option;
    if ( option == 1)
    { dice = rand() % 6 + 1;
    one = one + dice;
    cout << "You rolled a " << dice << "." << endl;}
    else return 0;

    that is my code to try and stop it from doing an infinite loop but it only works if the value is a number, other characters ( a,b,c, : , ; ) and things like that send it on an infinite loop and i don't really understand why.

  12. #12
    Not bad for a simple program. I went through just as 1 player. Only thing incorrect I noticed, is when I finished, it was in 15 turns, and it said I finished in 29 turns. As well as the missing instructions as already mentioned. Sadly I can't offer any coding advice, I haven't done anything with C++ since my senior year of high school, which was almost 10 years ago. I may still be able to gack something together in basic though
    http://us.battle.net/wow/en/characte...monzi/advanced

    Quote Originally Posted by Crokey View Post
    You know you just wrote 7 paragraphs about some people you have never met, playing a computer game in a way you disagree with?

  13. #13
    Also, besides fixing the hyphen infi loop and the crashing based on variable mismatch: make it so you cannot have more than 1 player with the same name. It doesn't cause game play issues, but it is still a problem having 4 people named t3hj0j0.

    Also: Is the board randomly generated every time? Or is it the same board?
    It's not just me, it's ALL rets. Join the ret MS club, get bitches, get money, get nerfed.
    It takes idiots to do cool things. That's why they're cool.

  14. #14
    Deleted
    Well.. I can't tell you much about making it better without the source code. You need good code to learn, not just a good executable.

    And i don't think (or at least i hope), that you C++ final should be marked by code, not by executable (although it is somewhat important to actually have it working ).


    About that input issue: Maybe you should read everthing into a string and parse that string for the given type you want (i.e. boost::lexical_cast or atof( inputString.c_str()) ). That way you should be able to avoid these loops (although it adds some runtime to the programm, which you won't notice anyways)
    Last edited by mmocb60793f883; 2011-04-19 at 11:38 PM.

  15. #15
    Bloodsail Admiral Dassen's Avatar
    10+ Year Old Account
    Join Date
    Jan 2010
    Location
    Sweden
    Posts
    1,087
    My current programming teacher said something that was very true at the start of this terms programming class.
    He held his hands about a foot apart and said "In order to make a program that works for you, that knows how to use it, the code needs to be this long." Then he held his hands 3~4 feet apart and said "However, in order to make the program idiot-proof, the code needs to be this long."

    So, so, SO true.
    "After dealing with about 10 000 patients over the last 15 years, I would say that over 200 different medical conditions respond favorably to cannabis."
    - The late Dr. Tod Mikuriya, MD, interview in The Union: The business behind getting high
    Former national administrator of the U.S. Government's marijuana research programs
    http://yourlogicalfallacyis.com/home

  16. #16
    //Lotto simulator 7-39;
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    #include <conio.h>
    using namespace std;
    int main(){

    int e1,e2,e3,e4,e5,e6,e7,e,b,b1,f,a1,a2,a3,a4,a5,a6,a7,u=0,n=0,n1=0,n2=0,n3=0,n4=0,n5=0,n6=0;
    srand(time(NULL));


    cout << "Input numbers between 1-39!"<<endl;
    cin >> a1;
    cin >> a2;
    cin >> a3;
    cin >> a4;
    cin >> a5;
    cin >> a6;
    cin >> a7;

    cout << a1<<"-"<<a2<<"-"<<a3<<"-"<<a4<<"-"<<a5<<"-"<<a6<<"-"<<a7<<endl;
    cout << "How much time do you want to simulate?"<<endl;
    cin >> b1;
    for(b=1;b<=b1;b++){
    u++;
    B: e1=rand()%39+1;
    e2=rand()%39+1;
    e3=rand()%39+1;
    e4=rand()%39+1;
    e5=rand()%39+1;
    e6=rand()%39+1;
    e7=rand()%39+1;
    A: if(e1==e7){e1=rand()%39+1;goto A;}
    if(e1==e6){e1=rand()%39+1;goto A;}
    if(e1==e5){e1=rand()%39+1;goto A;}
    if(e1==e4){e1=rand()%39+1;goto A;}
    if(e1==e3){e1=rand()%39+1;goto A;}
    if(e1==e2){e1=rand()%39+1;goto A;}
    if(e2==e7){e2=rand()%39+1;goto A;}
    if(e2==e6){e2=rand()%39+1;goto A;}
    if(e2==e5){e2=rand()%39+1;goto A;}
    if(e2==e4){e2=rand()%39+1;goto A;}
    if(e2==e3){e2=rand()%39+1;goto A;}
    if(e2==e1){e2=rand()%39+1;goto A;}
    if(e4==e7){e4=rand()%39+1;goto A;}
    if(e4==e6){e4=rand()%39+1;goto A;}
    if(e4==e5){e4=rand()%39+1;goto A;}
    if(e4==e3){e4=rand()%39+1;goto A;}
    if(e4==e2){e4=rand()%39+1;goto A;}
    if(e4==e1){e4=rand()%39+1;goto A;}
    if(e3==e7){e3=rand()%39+1;goto A;}
    if(e3==e6){e3=rand()%39+1;goto A;}
    if(e3==e5){e3=rand()%39+1;goto A;}
    if(e3==e4){e3=rand()%39+1;goto A;}
    if(e3==e2){e3=rand()%39+1;goto A;}
    if(e3==e1){e3=rand()%39+1;goto A;}
    if(e5==e7){e5=rand()%39+1;goto A;}
    if(e5==e6){e5=rand()%39+1;goto A;}
    if(e5==e4){e5=rand()%39+1;goto A;}
    if(e5==e3){e5=rand()%39+1;goto A;}
    if(e5==e2){e5=rand()%39+1;goto A;}
    if(e5==e1){e5=rand()%39+1;goto A;}
    if(e6==e7){e6=rand()%39+1;goto A;}
    if(e6==e5){e6=rand()%39+1;goto A;}
    if(e6==e4){e6=rand()%39+1;goto A;}
    if(e6==e3){e6=rand()%39+1;goto A;}
    if(e6==e2){e6=rand()%39+1;goto A;}
    if(e6==e1){e6=rand()%39+1;goto A;}
    if(e7==e6){e7=rand()%39+1;goto A;}
    if(e7==e5){e7=rand()%39+1;goto A;}
    if(e7==e4){e7=rand()%39+1;goto A;}
    if(e7==e3){e7=rand()%39+1;goto A;}
    if(e7==e2){e7=rand()%39+1;goto A;}
    if(e7==e1){e7=rand()%39+1;goto A;}
    cout << "Simulation " << u << " "<< e1<< "-" << e2<< "-" << e3<< "-" << e4<< "-" << e5<< "-" << e6<< "-" << e7<<endl;;
    if (a1 == e1){
    n=n+1;
    if(a2==e2){n1=1+n1;
    if(a3==e3){n2=1+n2;
    if(a4==e4){n3=n3+1;
    if(a5==e5){n4=n4+1;
    if(a6==e6){n5=n5+1;
    if (a7==e7){n6=n6+1;}}}}}}
    }

    }
    cout << "-----RESULT-----"<<endl;
    cout << "1 number right: " << n <<endl;
    cout << "2 numbers right: " << n1 <<endl;
    cout << "3 numbers right: " << n2 <<endl;
    cout << "4 numbers right: " << n3 <<endl;
    cout << "5 numbers right: " << n4 <<endl;
    cout << "6 numbers right: " << n5 <<endl;
    cout << "7 numbers right: " << n6 <<endl;
    cout << "spen: "<< u << "dollars!";





    getch ();
    return 0;
    }

    Need little help, not expert so not really pro with arrays. What it is its lotto simulator

  17. #17
    Quote Originally Posted by t3hj0j0 View Post
    Also, besides fixing the hyphen infi loop and the crashing based on variable mismatch: make it so you cannot have more than 1 player with the same name. It doesn't cause game play issues, but it is still a problem having 4 people named t3hj0j0.

    Also: Is the board randomly generated every time? Or is it the same board?
    It is the same board... it would be cool to randomly generate it but I don't posses the knowledge yet to do that... or maybe i do i just can't think of how atm.

  18. #18
    if (!(cin >> option);
    {
    cin.clear();
    cin.ignore(1000, '\n'
    cout << "Please only enter numeric values";
    }

    if ( option == 1)
    { dice = rand() % 6 + 1;
    one = one + dice;
    cout << "You rolled a " << dice << "." << endl;}
    else return 0;





    That should work for you but let me know

    Also about the random board you could easily do it with an array if you want to try that, but I'll let you at least try it yourself first since it's your project
    Last edited by Zulandia; 2011-04-19 at 11:38 PM.

  19. #19
    Deleted
    You know you've spent too much time reading science when you click on the thread thinking it's about Carbon ions.

    Seriously though, what is it?

  20. #20
    Deleted
    About that input issue: Maybe you should read everthing into a string and parse that string for the given type you want (i.e. boost::lexical_cast<double> or something like atof( inputString.c_str()) ). That way you should be able to avoid these loops (although it adds some runtime to the programm, which you won't notice anyways)

    @shaqur: well.. that's just horrible code. get rid of that goto and learn to use arrays. it's so much easier to cheack if a given number is already in an array than your approach is.
    Last edited by mmocb60793f883; 2011-04-19 at 11:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •