Simple integer Expression!

Discussion in 'C++' started by ianenis.tiryaki@gmail.com, Mar 23, 2007.

  1. Guest

    well i wrote this code but it doesn't work and shows me bunch of
    syntax if you can help me out finding them i would appreciate it!

    the program should do simple calculations and no parenthesis are
    allowed.so it is basically really simple but i am new at programming
    and not sure about my code. Thank you!

    here is my code:

    #include <iostream>
    #include <string>
    #include <iostream.h>
    using namespace std;

    void main()

    {
    int b, c ; //declearing the variables
    int reply;
    int output;


    cout << "Please enter 2 numbers" << endl;
    cin >> b >> c;
    cout <<"The Value of b: " << b << endl;
    cout <<"The Value of c: " << c << endl;
    cout << "please type '+' for abstraction, '-' for substraction,
    '/' for division, and '*' for multipication"<< endl;
    cin >> reply >>;

    if (reply= + ) {
    output = b + c;
    }

    else if (reply = - ) {
    output = b - c;
    }

    else if (reply = / ) {
    output = b / c;
    }
    else if (reply = * ) {
    output = b * c;
    }

    cout << "output: " << output << endl;

    // This section stops the program 'flashing' off the screen.

    cout << "Press q (or any other key) followed by 'Enter' to quit:
    ";
    cin >> reply;
    return 0;

    }
     
    , Mar 23, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

    wrote:
    > well i wrote this code but it doesn't work and shows me bunch of
    > syntax if you can help me out finding them i would appreciate it!
    >
    > the program should do simple calculations and no parenthesis are
    > allowed.so it is basically really simple but i am new at programming
    > and not sure about my code. Thank you!
    >
    > here is my code:
    >
    > #include <iostream>
    > #include <string>
    > #include <iostream.h>


    Loose this.
    > using namespace std;
    >
    > void main()
    >

    main returns int.
    > {
    > int b, c ; //declearing the variables


    Superfluous comment.

    > int reply;


    Wrong type.
    > int output;
    >
    >
    > cout << "Please enter 2 numbers" << endl;
    > cin >> b >> c;
    > cout <<"The Value of b: " << b << endl;
    > cout <<"The Value of c: " << c << endl;
    > cout << "please type '+' for abstraction, '-' for substraction,
    > '/' for division, and '*' for multipication"<< endl;
    > cin >> reply >>;
    >

    Too many >>
    > if (reply= + ) {


    Quote the the characters.

    > output = b + c;
    > }
    >
    > else if (reply = - ) {
    > output = b - c;
    > }
    >
    > else if (reply = / ) {
    > output = b / c;
    > }
    > else if (reply = * ) {
    > output = b * c;
    > }
    >
    > cout << "output: " << output << endl;
    >
    > // This section stops the program 'flashing' off the screen.
    >
    > cout << "Press q (or any other key) followed by 'Enter' to quit:
    > ";
    > cin >> reply;
    > return 0;
    >
    > }
    >



    --
    Ian Collins.
     
    Ian Collins, Mar 23, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 22, 9:22 pm, Ian Collins <> wrote:
    > wrote:
    > > well i wrote this code but it doesn't work and shows me bunch of
    > > syntax if you can help me out finding them i would appreciate it!

    >
    > > the program should do simple calculations and no parenthesis are
    > > allowed.so it is basically really simple but i am new at programming
    > > and not sure about my code. Thank you!

    >
    > > here is my code:

    >
    > > #include <iostream>
    > > #include <string>
    > > #include <iostream.h>

    >
    > Loose this.
    >
    > > using namespace std;

    >
    > > void main()

    >
    > main returns int.
    > > {
    > > int b, c ; //declaring the variables

    >
    > Superfluous comment.
    >
    > > int reply;

    >
    > Wrong type.
    >
    > > int output;

    >
    > > cout << "Please enter 2 numbers" << endl;
    > > cin >> b >> c;
    > > cout <<"The Value of b: " << b << endl;
    > > cout <<"The Value of c: " << c << endl;
    > > cout << "please type '+' for abstraction, '-' for substraction,
    > > '/' for division, and '*' for multipication"<< endl;
    > > cin >> reply >>;

    >
    > Too many >>
    > > if (reply= + ) {

    >
    > Quote the the characters.
    >
    >
    >
    > > output = b + c;
    > > }

    >
    > > else if (reply = - ) {
    > > output = b - c;
    > > }

    >
    > > else if (reply = / ) {
    > > output = b / c;
    > > }
    > > else if (reply = * ) {
    > > output = b * c;
    > > }

    >
    > > cout << "output: " << output << endl;

    >
    > > // This section stops the program 'flashing' off the screen.

    >
    > > cout << "Press q (or any other key) followed by 'Enter' to quit:
    > > ";
    > > cin >> reply;
    > > return 0;

    >
    > > }

    >
    > --
    > Ian Collins.


    so man how can i identify "reply" if you say int is not the right way?
     
    , Mar 23, 2007
    #3
  4. Tim H Guest

    On Mar 22, 9:22 pm, Ian Collins <> wrote:

    You're much nicer than I would be with these homework problems.
     
    Tim H, Mar 23, 2007
    #4
  5. Guest

    ????
     
    , Mar 23, 2007
    #5
  6. Ian Collins Guest

    wrote:
    > On Mar 22, 9:22 pm, Ian Collins <> wrote:
    >>
    >>> int reply;

    >>
    >>Wrong type.
    >>
    >>> if (reply= + ) {


    I won't ask you again not to quote signatures, I'll just ignore you.
    >
    > so man how can i identify "reply" if you say int is not the right way?
    >

    Well what type is it? Hint, what do you compare it against (and how are
    you comparing)?

    --
    Ian Collins.
     
    Ian Collins, Mar 23, 2007
    #6
  7. Ian Collins Guest

    Tim H wrote:
    > On Mar 22, 9:22 pm, Ian Collins <> wrote:
    >
    > You're much nicer than I would be with these homework problems.
    >

    I think hints rather than answers are acceptable for homework questions.
    Direct answers don't to the OP any favours.

    --
    Ian Collins.
     
    Ian Collins, Mar 23, 2007
    #7
  8. osmium Guest

    <> wrote:

    > well i wrote this code but it doesn't work and shows me bunch of
    > syntax if you can help me out finding them i would appreciate it!
    >
    > the program should do simple calculations and no parenthesis are
    > allowed.so it is basically really simple but i am new at programming
    > and not sure about my code. Thank you!
    >
    > here is my code:
    >
    > #include <iostream>
    > #include <string>
    > #include <iostream.h>


    Choose a form and stick with it. Either <iostream> (preferred) or
    <iostrream.h> if your compiler won't accept the modern form.

    > using namespace std;
    >
    > void main()
    >
    > {
    > int b, c ; //declearing the variables
    > int reply;
    > int output;
    >
    >
    > cout << "Please enter 2 numbers" << endl;
    > cin >> b >> c;
    > cout <<"The Value of b: " << b << endl;
    > cout <<"The Value of c: " << c << endl;
    > cout << "please type '+' for abstraction, '-' for substraction,
    > '/' for division, and '*' for multipication"<< endl;
    > cin >> reply >>;
    >
    > if (reply= + ) {


    You want the symbol + to be treated as a character constant. *Proper*
    character constants are indicated like this:

    if(reply = '+') {

    This has repercussions elsewhere in your program.

    Furthermore you want == which tests for equality, not = which is the
    replacement operator in C++.


    > output = b + c;
    > }
    >
    > else if (reply = - ) {
    > output = b - c;
    > }
    >
    > else if (reply = / ) {
    > output = b / c;
    > }
    > else if (reply = * ) {
    > output = b * c;
    > }
    >
    > cout << "output: " << output << endl;
    >
    > // This section stops the program 'flashing' off the screen.
    >
    > cout << "Press q (or any other key) followed by 'Enter' to quit:
    > ";
    > cin >> reply;
    > return 0;
    >
    > }
    >
     
    osmium, Mar 23, 2007
    #8
  9. red floyd Guest

    Tim H wrote:
    > On Mar 22, 9:22 pm, Ian Collins <> wrote:
    >
    > You're much nicer than I would be with these homework problems.
    >


    Actually, he's OK here. He is apparently trying, and posting what he
    did do, in accordance with FAQ 5.2.
     
    red floyd, Mar 23, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,970
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  2. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    No Math.min(Integer, Integer)?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Jul 29, 2003, in forum: Java
    Replies:
    0
    Views:
    525
    =?ISO-8859-1?Q?Thomas_Gagn=E9?=
    Jul 29, 2003
  3. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    2
    Views:
    514
    Yu SONG
    Oct 15, 2004
  4. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    6
    Views:
    45,650
    JavaBean2010
    Apr 7, 2010
  5. Johannes Zellner
    Replies:
    22
    Views:
    3,679
Loading...

Share This Page