Thread: category of Math signs???

  1. #1
    Registered User
    Join Date
    Jan 2004

    category of Math signs???

    what category do mathmatical signs fall under?

    I'm very new to C++, i'm trying to make a calculator. How do you get it to read math signs as input like intergers??

    enter first value:

    enter math opperation:

    **If "+" do this
    if "-" do this

    enter second value:


    ** What code will get it to take that as input?

  2. #2
    Registered User
    Join Date
    Mar 2002
    use a variable of type char to hold the math sign and then a switch statement to evaluate and do:

    int var1
    int var2
    char sign
    cout << enter value for var1
    cin >> var1
    cout << enter sign
    cin >> sign
    cout << enter value for var2

    cout << var1 + var2
    cout << var1 * var2

  3. #3
    Registered User
    Join Date
    Nov 2003
    you have to convert string to integers. use atoi char to int and itoa int to char. for if statements its done like this

    if(character == '+') { do this;} else {do that;}
    "+" is not the same as '+'

    use cout to put stuff on screen e.g.

    cout << "hello world";

    use cin to get user input e.g.

    char f[3];
    cin >> f;

    don't forget to put this line at the top;

    #include "iostream.h"

    that is for cout and cin

    #include "stdlib.h"

    that is for itoa and atoi.

    Hope that helps!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math
    By knightjp in forum A Brief History of
    Replies: 16
    Last Post: 04-01-2009, 05:36 PM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  3. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  4. Math Header?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 09-17-2004, 06:39 AM
  5. toughest math course
    By axon in forum A Brief History of
    Replies: 12
    Last Post: 10-28-2003, 10:06 PM