Thread: My calculator program. Final fixes.

  1. #1
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079

    My calculator program. Final fixes.

    OK! I almost made my calculator me proof! (read: idiot proof; ...if you knew me, that'd be funnier. Err... wait. Actually after all of this, you'll probably find it funny. Well, you will after my question, anyway... I like questions. You know what my favorite question is? ... ...Ok, now you think I'm an idiot.}

    Anyway, I have one last problem with my calculator. All of the "Improper value" warnings only work if the improper value is a number. If it's any other character, my program crashes.
    This is because the variables that this "Improper value" warning acts on is an integer. ¬_¬

    So what can I define the variable as so that it works for both characters and numbers?

    --SlyMaelstrom
    "My favorite question is: 'Jigga what?' "

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You could read in a std::string from the <string> header, and then write a function to convert it to a number. If it fails, then just print your message.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Additionally, there are a few functions from the C library that might help you out: http://cppreference.com/stdstring.html

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    5
    Using Zach L. stuff is probably the easist. Using atoi(); to convert over to an integer again .
    Example usage of atoi():
    Code:
    char buffer[] = "142525";
    int intBuffer;
    intBuffer = atoi(buffer);
    hehe, I tried my best to show you

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    overuseness of teh word 'buffer':
    Code:
    char words[] = "142525";
    int number;
    number = atoi(words);
    my code =your code + better names
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I dislike the name 'words'. It doesn't truly reflect the content of the variable; probably 'characters' or 'digits', or in this case even 'input' is more appropriate.

    My name = (your name)++
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    me too, but class was ending and I couldn't think of anything else before I had to leave... I used to use string, but then people think you're using C++ strings...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    How about 'str', or 'inStr'?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX dll Final Debug and Final Retail
    By hdragon in forum Tech Board
    Replies: 0
    Last Post: 11-15-2005, 09:46 PM
  2. Studying for Final, Couple Questions...
    By stewade in forum C Programming
    Replies: 4
    Last Post: 05-10-2004, 05:02 PM
  3. reviewing for final exam, need help with this question
    By jlmac2001 in forum C++ Programming
    Replies: 12
    Last Post: 11-26-2003, 08:37 AM
  4. Final year project
    By khpuce in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 10-10-2003, 07:04 AM
  5. Final Fantasy XI. PC or PS2...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-21-2001, 11:57 PM