Thread: C++ removing cout ??

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    22

    C++ removing cout ??

    Hey im just making a game called yahtzee if anyone knows it for school and im having trouble with one part.
    Let me explain the way the teacher wants the game to work. The are thirteen possible scores that the user can choose from after the dice roll randomly, then then next time the user can choose from the list of possible scoring systems again minus the one they already chose, all the way untill all thirteen scores are gone then the game prints the final score.
    I was thinking of initalising the thirteen scoring outputs or something so anyway talked to much here is a segment of my code:

    cout<<"\nPlease chose your scoreing system - remember you may only choose each one once: "<<endl;

    cout<<"\n1. Ones - Adds all the ones to your score"<<endl;
    cout<<"2. Twos - Adds all the twos to your score"<<endl;
    cout<<"3. Threes - Adds all the threes to your score"<<endl;
    cout<<"4. Fours - Adds all the fours to your score"<<endl;
    cout<<"5. Fives - Adds all the fives to your score"<<endl;
    cout<<"6. Sixs - Adds all the sixs to your score"<<endl;
    cout<<" "<<endl;

    cin>>userchoice;

    so after user inputs i can compare and all just need to remove output from appearing next loop.

    any help will be appreciated

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, build a table (of struct or class entries) that contains the text, which choice to select to use it ("1", "2" etc), and the result and a bool to indicate that the selection is available or not. Print only available entries for the user to choose from. Once it's "been used" set available to false.

    When checking which choice was entered, run through the table and compare the choices with the choice the user used, and check that it's available (users are stupid, so they will press "2" even after choice 2 has been taken, so you need to make sure this "does the right thing", such as say "That choice isn't available").


    --
    Mats

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    22
    so just as an example how would i create (well ive never used it so ill refer to int) liek the int value of that
    like

    char 1 = "ones ........ etc"

    then remove from there, caus ethat what i was thinken of doing but dont know the right initalising name

    sorry for stupid question new to this and all

    thnx again

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, so you probably need to learn a little bit more C/C++ programming before what I said makes any sense. Try looking at tutorials for "struct".

    --
    Mats

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    22
    haha i know this is getting annoying but we are only allowd to use upto what weve lernt, im in week 7 of school now, we just lernt arrays. alot of students get marked down for useing more advanced stuff than what weve lernt.
    so i kinda have to make the program well stupid but functional.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, so you use multiple arrays (one for string description ("ones", "twos", "full house", etc), one for which alternatives are available and not, and one for the resuling score for each entry) - it may be a good idea to discuss in some way with your teacher if that approach is OK - I'm sure that if you DISCUSS the idea, your teacher (or whoever is at hand to help you) will be able to help you with understanding the if your approach is OK or not.

    --
    Mats

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    22
    thnx, ill look into what you said, ive been looking round for hours now, its just that most teachers - especially in programming are very unaproachable, kinda upthemselfs, like you should know everything they know or your just an annoyance, hate doing that so i just come here

    thnx again

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If you're paying for the course, then you should be learning from them. You should ask them for help.

    I hate when teachers punish students for being advanced. If you already know the language, I think the last thing on your mind when you're about to do your assignment is, "What did we just cover up to now since that's all I can use?"

    If you covered functions, you could make a new function to return the string version of your int. Corresponding arrays are probably better as matsp suggested, but there's more than one way to go about it.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, being punished for using things you shouldn't is plain wrong, _UNLESS_ you are avoiding doing the task - e.g. calling strtol() isn't exactly writing some code to convert a string to integer.

    Also, using an advanced method to solve a problem should be UNDERSTOOD by the student, not just "I've done this and it works, but I don't know why".

    --
    Mats

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I agree.

    If an assignment states, "Compute xyz using recursion." then obviously recursion should be used, and the test there is probably to see if the student understands and can utilize recursion to solve a simple task. If the assignment just says, "Compute xyz." and recursive solutions are docked because it hasn't been covered in class yet, that's on the stupid side.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by MacGyver View Post
    If you covered functions, you could make a new function to return the string version of your int. Corresponding arrays are probably better as matsp suggested, but there's more than one way to go about it.
    You'd still need some sort of array to know which entries the user has "used up" and which hasn't been taken yet - that's the key question in the original post, he poster wants to "remove" things that have been used. We obviously can't remove the "cout" itself, so we have to have a list of which ones can be used or not.

    [Edit: of course, it's technically possible to write self-modifying code to remove parts of the code, but that isn't within the scope of the original posters class, I would expect - nor would I recommend it for ANY other purpose either, except tiny embedded systems perhaps]

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class methods to cout stream
    By shintaro in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2008, 07:27 PM
  2. How Does cout Work
    By jrahhali in forum C++ Programming
    Replies: 8
    Last Post: 08-25-2004, 03:19 PM
  3. cout vs std::cout
    By none in forum C++ Programming
    Replies: 10
    Last Post: 07-26-2004, 11:20 PM
  4. c++ string input
    By R.Stiltskin in forum C++ Programming
    Replies: 4
    Last Post: 02-22-2003, 04:25 PM
  5. FAQ cout
    By evilmonkey in forum FAQ Board
    Replies: 1
    Last Post: 10-07-2001, 11:32 AM