Need C++ help..

Discussion in 'Software' started by DarkFable, Oct 27, 2005.

  1. DarkFable

    DarkFable Private E-2

    Ok tomorrow i have a C++ test in my grade 11 computer science course and my teacher gave us a few questions to practise at home (I'm using Visual C++ from Visual Studio 6.0 Enterprise). Heres the problem:

    Problem 1. Have the user input a 4-digit character array or string. Have your program convert this string into an integer value without using the atoi function.

    As it clearly states, i cannot use the atoi function. Now a previous question wanted the opposite (integer to char array) with itoa function and i got that working with the code i have in the txt file.

    Problem 2. Have the user guess at random number. Have the computer tell the user either “Higher” or “Lower” until correct. The program will show the total number of guesses. Also, if the user is a moron, tell them so. For example, assume the correct number is 12. If the user inputs 7 and your program informs the user “higher”, if at any later time the user inputs a number of 7 or lower, the program is permitted to call the user a “moron”.


    My question is if someone can please code this for me because i have missed that last 4 days of school with the flu and am i little behind. Also, if you could code it at a similar level as the code in the txt file, i would really appriciate it because thats how far our class as gotten so far. Please refer to the text file.

    Thanks in advance,
    Marko
     

    Attached Files:

  2. Wookie

    Wookie Sergeant Major



    Im not going to code it for you but thats pretty simple, use the rand function to put a random number into a variable, ask for user input, your going to want to use some sort of loop for this, you want to loop until they get it correct. Your going to want to have a couple variables, a lowset guess, highest guess and last guess.

    During each iteration of the loop you want to get the number, check to see if the number is higher, higher than the highest guess, lower, lower than the lowest guess or equal to the correct answer, Your of course going to use some sort of logic like and IF statement, depending on what is found your going to either possibly display "moron", Tell them if its higher or lower or tell them they got it right and break the loop.

    I dont mind helping but dont ask people to do your work for you. Thats just lazy.
     
  3. walter34payton2002

    walter34payton2002 Specialist

    Kid, you make me laugh, and I mean that in a good way. What if teach is a major geek, man? I don't remember how I did it in 11th grade, but I've missed a class or two in college. The way I would do it is just read the text. It may take a while longer, but everything you need should be in the text. Think of it as good college prep, my man.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds