Help!

This is a discussion on Help! within the C++ Programming forums, part of the General Programming Boards category; can somebody help me with this program? #include <iostream.h> #include <windows.h> int main() { cout << "Stephen's C++ Calculator" << ...

  1. #1
    gcn_zelda
    Guest

    Unhappy Help!

    can somebody help me with this program?

    #include <iostream.h>
    #include <windows.h>

    int main()
    {
    cout << "Stephen's C++ Calculator" << endl;
    cout << "Enter a number" << endl;
    int a;
    cin << a;
    cout << a << endl;
    cout << "Now push a math sign" << endl;
    int sign;
    cin << sign;
    cout << a <<""<< sign << endl;
    cout << "Now push a second number" << endl;
    int b;
    cin << b;
    if (sign == " + ");
    {
    int resultplus;
    a + b = resultplus;
    cout << resultplus << " is your answer!" << endl;
    }
    if(sign == " - ");
    {
    int resultminus;
    a - b = resultminus;
    cout << resultminus << " is your answer!" << endl;
    }
    if(sign == "/");
    {
    int resultdivide;
    a / b = resultdivide;
    cout << resultdivide << " is your answer!" << endl;
    }
    if(sign == "*");
    {
    int resultmultiply;
    a * b = resultmultiply;
    cout << resultmultiply << " is your answer!" << endl;
    }
    return 0;
    }

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >>can somebody help me with this program?

    Sure! But first format your code using code tags, and tell us the problem!

  3. #3
    ThisNukes4u
    Guest

    Talking

    Your "if" statements have semicolons at the end.

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    sorry. i wasn't logged in

    line 9, 13, 17- no match for '_IO_istream_withassign& << int&
    and a whole bunch of non- |value in assignment
    and ANSI C++ comparison between pointer and integer

  5. #5
    ThisNukes4u
    Guest
    And your "<<" on cin is supposed to be ">>".

  6. #6
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    thanks, y'all!

  7. #7
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    ; on if is wrong, so is the direction of your operators on the cin lines. Also sign should be a char and encased in '' not "", heres a fixed version.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    cout << "Stephen's C++ Calculator" << endl;
    cout << "Enter a number" << endl;
    int a;
    cin >> a;
    cout << a << endl;
    cout << "Now push a math sign" << endl;
    char sign;
    cin >> sign;
    cout << a <<" "<< sign << endl;
    cout << "Now push a second number" << endl;
    int b;
    cin >> b;
    if (sign == '+')
    {
    int resultplus;
    resultplus = a + b;
    cout << resultplus << " is your answer!" << endl;
    }
    if(sign == '-')
    {
    int resultminus;
    resultminus = a - b;
    cout << resultminus << " is your answer!" << endl;
    }
    if(sign == '/')
    {
    int resultdivide;
    resultdivide = a / b;
    cout << resultdivide << " is your answer!" << endl;
    }
    if(sign == '*')
    {
    int resultmultiply;
    resultmultiply = a*b;
    cout << resultmultiply << " is your answer!" << endl;
    }
    return 0;
    }
    Last edited by RoD; 03-14-2003 at 09:42 PM.

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    Code:
    int this_is_input;
    cin >> this_is_input;
    cout << "this is output";
    ...
    if (false);                           // <--- awnser                               
       this_will_always_execute(); //why?
    ...
    int give_me_a_value;
    give_me_a_value = 10 - 5; //NOT 10 - 5 = give_me_a_value
    ...
    //input a char
    char op;
    cin >> op;
    //compare a char
    if (op == '+') {...}
    Read your C++ book, and use code tags when posting code.

    gg

    [EDIT]
    wow, I'm a slow typer....your homework is done, now study your C++ book!!
    Last edited by Codeplug; 03-14-2003 at 09:45 PM.

  9. #9
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    don't have a C++ book

  10. #10
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Naviagte to the main site and read the tutorials. No offense intended, but you should start small, you had alot of syntax errors in there.

  11. #11
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    I already know BASIC, so I learn from experience

  12. #12
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    The tutorials are a good place to start. I'm not saying go back to "Hello World" or anything, but a good tutorial never hurts.

  13. #13
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    right

    when i run my edited program in Dev C++, it doesn't do anything even though it was compiled correctly.

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