category of Math signs???

This is a discussion on category of Math signs??? within the C++ Programming forums, part of the General Programming Boards category; what category do mathmatical signs fall under? I'm very new to C++, i'm trying to make a calculator. How do ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    8

    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
    ect.

    enter second value:

    answer



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

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


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

    switch(sign)
    case('+'):
    cout << var1 + var2
    break
    case('*')
    cout << var1 * var2
    break

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

    Code:
    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 Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 06: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, 08:22 PM
  4. Math Header?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 09-17-2004, 07:39 AM
  5. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 10:06 PM

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