Thread: question about "random" and a calculator

  1. #16
    Registered User
    Join Date
    Mar 2010
    Posts
    7
    so use if statements?

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by godofal View Post
    so use if statements?
    Sounds like a plan to me. If you read in the op as a single character, you can get really fancy and use switch.

  3. #18
    Registered User
    Join Date
    Mar 2010
    Posts
    7
    well, i used those if statements, and it works now!
    i had some difficulties becouse i used = instead of == first, but figured that out, and now it works olmost completely as it should.

    the 2 issues i still have are that i needed to use numbers instead of operators. so in the program, 1 represents +, 2 means -, 3 uses *, and 4 /.

    and, i cannot use decimal(not sure if theyr called that way) numbers like 1.5, just whole numbers like 1...

    im think ive read somewhere how to fix that first issue, and maybe i can fix the second also.

    i have included the code in this reply.

    edit:
    i have used long double to make decimal numbers possible, ive tested it and it works

    edit2:
    i cant get OP1 to accept characters like +,-,* or /
    i have tried making OP1 a char integer, and use the:
    if ( OP1 == + ) {
    NR3= NR1 + NR2; //use if OP1 is 1 (+)
    }
    statement (and the other operators likewise)
    but codeblocks says:
    main.cpp|20|error: expected primary-expression before ')' token|

    how do i get this to work??
    Last edited by godofal; 03-19-2010 at 07:03 AM.

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    + is not a character. '+' is a character.

  5. #20
    Registered User
    Join Date
    Mar 2010
    Posts
    7
    im going to try that next!
    *crosses fingers*

    it works
    ive included the finished sourcecode.
    Last edited by godofal; 03-19-2010 at 12:45 PM.

Popular pages Recent additions subscribe to a feed