question about "random" and a calculator

This is a discussion on question about "random" and a calculator within the C++ Programming forums, part of the General Programming Boards category; so use if statements?...

  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,185
    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??
    Attached Files Attached Files
    Last edited by godofal; 03-19-2010 at 08:03 AM.

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    + 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.
    Attached Files Attached Files
    Last edited by godofal; 03-19-2010 at 01:45 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21