n00b help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christo

    #1

    n00b help

    borland c++ 5.01

    character constant must be one or two characters long

    get this when compiling my first c++ program can anyone out there help?

    it is highlighting this line as the problem

    cout << "Please Enter First number: ";

    that is correct isnt it though?

    here is the code i have used...

    #include <iostream.h>
    void main (void)
    {
    int iFirst, iSecond, iAnswer;
    char cOperator, cCmd;
    cout << endl;
    cout << endl;
    cout << "Press any key to start the program or type help to view help: ";
    cin >> cCmd; endl;
    if (cCmd == 'help')
    cout << "Help File" endl;
    cout << endl;
    cout << "Using this calculator is simple below is the key for the
    operators"; endl;
    cout << "+ = Add \n - = Subtract \n / = Divide \n * = Multiply";
    cout << endl;
    cout << "Please restart to program to continue"; endl;
    else
    cout << "Please select which operator would would like to use +/-: ";
    cin >> cOperator; endl;
    cout << "Please Enter First number: ";
    cin >> iFirst; endl;
    cout << "Please Enter Second Number: ";
    cin >> iSecond;
    if (cOperator == '+')
    iAnswer = iFirst+iSecond;
    else if
    (cOperator == '/')
    iAnswer = iFirst/iSecond;
    else if
    (cOperator == '-')
    iAnswer = iFirst-iSecond;
    else if
    (cOperator == '*')
    iAnswer = iFirst*iSecond;
    else
    cout << endl;
    cout << "****Please Input A Correct Operator****" endl;
    cout << "The Answer To your Sum is: ";
    cout << iAnswer;
    }


    i know it is probably not the easiest way to create a simple calculator but
    i know this way will work but i dont know what is casusing the failure when
    i try to compile

    any help would be much appreciated
    --
    Thanks,

    Chris.


  • John Harrison

    #2
    Re: n00b help


    "Christo" <chris@juststuf f.co.uk> wrote in message
    news:2u960iF27c ca8U1@uni-berlin.de...[color=blue]
    > borland c++ 5.01
    >
    > character constant must be one or two characters long
    >
    > get this when compiling my first c++ program can anyone out there help?
    >
    > it is highlighting this line as the problem
    >
    > cout << "Please Enter First number: ";
    >
    > that is correct isnt it though?[/color]

    Yes, but many other corrections needed.
    [color=blue]
    >
    > here is the code i have used...
    >
    > #include <iostream.h>[/color]

    #include <iostream>
    using namespace std;

    C++ does not have a header file called <iostream.h>, any one who tells you
    different is wrong. The cirrect header file is <iostream> without the .h.
    Many compilers however support <iostream.h> but you should not use it
    because it isn't proper C++. A few very old compilers do not have
    <iostream>, they only have <iostream.h>, if that is the case for you then
    you should get a better compiler. There are plently of free compilers
    available which support modern C++.
    [color=blue]
    > void main (void)[/color]

    int main()

    main always returns an int, again anyone whoe tells you different is wrong.
    [color=blue]
    > {
    > int iFirst, iSecond, iAnswer;
    > char cOperator, cCmd;
    > cout << endl;
    > cout << endl;
    > cout << "Press any key to start the program or type help to view help:[/color]
    ";[color=blue]
    > cin >> cCmd; endl;[/color]

    cin >> cCmd;
    [color=blue]
    > if (cCmd == 'help')[/color]

    OK here's your big mistake. You obviously think that cCmd can be any number
    of characters. But 'char cCmd' means a /single/ character. If you want
    multiple characters you should use strings and double quotes. For instance

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

    int main()
    {
    cout << "Press any key to start the program or type help to view help:
    ";
    string cmd;
    getline(cin, cmd);
    if (cmd == "help")

    Looks like you've forgotten to put curly brackets here

    {
    [color=blue]
    > cout << "Help File" endl;
    > cout << endl;
    > cout << "Using this calculator is simple below is the key for the
    > operators"; endl;
    > cout << "+ = Add \n - = Subtract \n / = Divide \n * = Multiply";
    > cout << endl;
    > cout << "Please restart to program to continue"; endl;[/color]

    And here

    }
    [color=blue]
    > else[/color]

    And here

    {

    and various other places.

    I think you are learning C++ from an out of date source, your code is
    old-fashioned. It would be a good idea to get a modern C++ text book.

    john


    Comment

    • Lionel B

      #3
      Re: n00b help

      Christo wrote:[color=blue]
      > borland c++ 5.01
      >
      > character constant must be one or two characters long[/color]

      Eh?
      [color=blue]
      > get this when compiling my first c++ program can anyone out there[/color]
      help?[color=blue]
      >
      > it is highlighting this line as the problem
      >
      > cout << "Please Enter First number: ";[/color]

      (and the error message is...?). In fact this line is not in itself a
      problem - many other things are.

      Hints:

      * Look up the if .. else ... syntax and find out about curly brackets.

      * Look up the difference between single and double quotes.

      * Look up what "endl" is/does and when/how to use it.

      Also:

      * Get a good C++ book - there are *many* things wrong with this program
      (which I'm sure other posters will point out to you) and the coding
      style is apalling.

      * Start with a simpler program - "Hallo world" is always good :)
      Regards,

      --
      Lionel B

      Comment

      • Rolf Magnus

        #4
        Re: n00b help

        Christo wrote:
        [color=blue]
        > borland c++ 5.01
        >
        > character constant must be one or two characters long
        >
        > get this when compiling my first c++ program can anyone out there help?
        >
        > it is highlighting this line as the problem
        >
        > cout << "Please Enter First number: ";[/color]

        Are you sure about that? See below.
        [color=blue]
        >
        > that is correct isnt it though?[/color]

        Yes.
        [color=blue]
        > here is the code i have used...
        >
        > #include <iostream.h>[/color]

        <iostream.h> is an outdated non-standard header. Use <iostream> instead.
        cout, cin and endl will then be in namespace std, so you need to add e.g.:

        using std::cout;
        using std::cin;
        using std::endl;
        [color=blue]
        > void main (void)[/color]

        main must return int. Nothing else is allowed by the C++ standard. Even if
        your compiler might accept it, there is no reason to violate the standard
        in this case.
        [color=blue]
        > {
        > int iFirst, iSecond, iAnswer;
        > char cOperator, cCmd;[/color]

        Note that each of cOperator and cCmd can hold exactly one single character.
        For cCmd, that is not enough, since it can't hold the string "help". So you
        should add #include <string> and using std::string; above, and then change
        the above line into:

        char cOperator;
        string cCmd;
        [color=blue]
        > cout << endl;
        > cout << endl;
        > cout << "Press any key to start the program or type help to view help:
        > "; cin >> cCmd; endl;[/color]

        The endl at the end doesn't do anything. It evaluates a function pointer and
        does nothing with it. You probably meant:

        cout << endl;
        [color=blue]
        > if (cCmd == 'help')[/color]

        Are you sure that this wasn't the line in question? 'help' is illegal, since
        character constants can hold one single character, but yours is 4
        characters long. If you make cCmd a string as mentioned above, you can
        write:

        if (cCmd == "help")
        [color=blue]
        > cout << "Help File" endl;
        > cout << endl;[/color]

        You're missing an operator << in the first of those two lines. Note also
        that endl does two things. It writes a \n to the output stream and flushes
        it. You don't need the flush here, so you could simply write:

        cout << "Help File\n\n";

        This saves you two unnecessary flushes and is less to type.
        [color=blue]
        > cout << "Using this calculator is simple below is the key for the
        > operators"; endl;[/color]

        Again a no-op at the end.
        [color=blue]
        > cout << "+ = Add \n - = Subtract \n / = Divide \n * = Multiply";
        > cout << endl;
        > cout << "Please restart to program to continue"; endl;[/color]

        And here.
        [color=blue]
        > else
        > cout << "Please select which operator would would like to use +/-: ";
        > cin >> cOperator; endl;[/color]

        And here again.
        [color=blue]
        > cout << "Please Enter First number: ";
        > cin >> iFirst; endl;[/color]

        And another one.
        Btw, what if the user enters something that isn't a nuber?
        [color=blue]
        > cout << "Please Enter Second Number: ";
        > cin >> iSecond;
        > if (cOperator == '+')
        > iAnswer = iFirst+iSecond;
        > else if
        > (cOperator == '/')
        > iAnswer = iFirst/iSecond;
        > else if
        > (cOperator == '-')
        > iAnswer = iFirst-iSecond;
        > else if
        > (cOperator == '*')
        > iAnswer = iFirst*iSecond;
        > else
        > cout << endl;
        > cout << "****Please Input A Correct Operator****" endl;
        > cout << "The Answer To your Sum is: ";
        > cout << iAnswer;
        > }[/color]

        Comment

        • Christo

          #5
          Re: n00b help


          "Rolf Magnus" <ramagnus@t-online.de> wrote in message
          news:clnq64$ip4 $02$1@news.t-online.com...[color=blue]
          > Christo wrote:
          >[color=green]
          >> borland c++ 5.01
          >>
          >> character constant must be one or two characters long
          >>
          >> get this when compiling my first c++ program can anyone out there help?
          >>
          >> it is highlighting this line as the problem
          >>
          >> cout << "Please Enter First number: ";[/color]
          >
          > Are you sure about that? See below.
          >[color=green]
          >>
          >> that is correct isnt it though?[/color]
          >
          > Yes.
          >[color=green]
          >> here is the code i have used...
          >>
          >> #include <iostream.h>[/color]
          >
          > <iostream.h> is an outdated non-standard header. Use <iostream> instead.
          > cout, cin and endl will then be in namespace std, so you need to add e.g.:
          >
          > using std::cout;
          > using std::cin;
          > using std::endl;
          >[color=green]
          >> void main (void)[/color]
          >
          > main must return int. Nothing else is allowed by the C++ standard. Even if
          > your compiler might accept it, there is no reason to violate the standard
          > in this case.
          >[color=green]
          >> {
          >> int iFirst, iSecond, iAnswer;
          >> char cOperator, cCmd;[/color]
          >
          > Note that each of cOperator and cCmd can hold exactly one single
          > character.
          > For cCmd, that is not enough, since it can't hold the string "help". So
          > you
          > should add #include <string> and using std::string; above, and then change
          > the above line into:
          >
          > char cOperator;
          > string cCmd;
          >[color=green]
          >> cout << endl;
          >> cout << endl;
          >> cout << "Press any key to start the program or type help to view help:
          >> "; cin >> cCmd; endl;[/color]
          >
          > The endl at the end doesn't do anything. It evaluates a function pointer
          > and
          > does nothing with it. You probably meant:
          >
          > cout << endl;
          >[color=green]
          >> if (cCmd == 'help')[/color]
          >
          > Are you sure that this wasn't the line in question? 'help' is illegal,
          > since
          > character constants can hold one single character, but yours is 4
          > characters long. If you make cCmd a string as mentioned above, you can
          > write:
          >
          > if (cCmd == "help")
          >[color=green]
          >> cout << "Help File" endl;
          >> cout << endl;[/color]
          >
          > You're missing an operator << in the first of those two lines. Note also
          > that endl does two things. It writes a \n to the output stream and flushes
          > it. You don't need the flush here, so you could simply write:
          >
          > cout << "Help File\n\n";
          >
          > This saves you two unnecessary flushes and is less to type.
          >[color=green]
          >> cout << "Using this calculator is simple below is the key for
          >> the
          >> operators"; endl;[/color]
          >
          > Again a no-op at the end.
          >[color=green]
          >> cout << "+ = Add \n - = Subtract \n / = Divide \n * = Multiply";
          >> cout << endl;
          >> cout << "Please restart to program to continue"; endl;[/color]
          >
          > And here.
          >[color=green]
          >> else
          >> cout << "Please select which operator would would like to use +/-:
          >> ";
          >> cin >> cOperator; endl;[/color]
          >
          > And here again.
          >[color=green]
          >> cout << "Please Enter First number: ";
          >> cin >> iFirst; endl;[/color]
          >
          > And another one.
          > Btw, what if the user enters something that isn't a nuber?
          >[color=green]
          >> cout << "Please Enter Second Number: ";
          >> cin >> iSecond;
          >> if (cOperator == '+')
          >> iAnswer = iFirst+iSecond;
          >> else if
          >> (cOperator == '/')
          >> iAnswer = iFirst/iSecond;
          >> else if
          >> (cOperator == '-')
          >> iAnswer = iFirst-iSecond;
          >> else if
          >> (cOperator == '*')
          >> iAnswer = iFirst*iSecond;
          >> else
          >> cout << endl;
          >> cout << "****Please Input A Correct Operator****" endl;
          >> cout << "The Answer To your Sum is: ";
          >> cout << iAnswer;
          >> }[/color]
          >[/color]

          Thank you, I gotta start learning from my mistakes, It's my university they
          insist on using borland c++ 5.01 which i think was released in mid 90's

          thanks all for the hwlp I am gonna go off and try to get it working


          Comment

          • Christo

            #6
            Re: n00b help



            we have not covered strings in the intro to c++ course yet at uni, just int,
            float and char, so i havent used them, i dont want to get confused early on,
            even though i have programmed before with vb and used php i think c++ is
            going to be a step up for me.

            I got the program working with one minor problem... whenever i get my answer
            it prints this line regardless if i input the correct operator (+ - * /)

            can anyone give me any advice... it shouldnt print this since it was a
            correct operator should it.

            here is the code now........

            #include <iostream>

            int main()
            {
            int iFirst, iSecond, iAnswer;
            char cOperator, cCmd;
            cout << endl;
            cout << endl;
            cout << "Press any key to start the program or type *h* to view help: ";
            cin >> cCmd; endl;
            if (cCmd == 'h')
            {
            cout << "Help File" << endl;
            cout << endl;
            cout << "Using this calculator is simple below is the key for the
            operators";
            cout << "\n + = Add \n - = Subtract \n / = Divide \n * = Multiply";
            cout << endl;
            cout << "Please restart to program to continue"; endl;
            }
            else
            {
            cout << "Please select which operator would would like to use +/-: ";
            cin >> cOperator; endl;
            cout << "Please Enter First number: ";
            cin >> iFirst; endl;
            cout << "Please Enter Second Number: ";
            cin >> iSecond;
            if (cOperator == '+')
            {
            iAnswer = iFirst+iSecond;
            }
            else if (cOperator == '/')
            {
            iAnswer = iFirst/iSecond;
            }
            else if (cOperator == '-')
            {
            iAnswer = iFirst-iSecond;
            }
            else if (cOperator == '*')
            {
            iAnswer = iFirst*iSecond;
            }
            else
            {
            cout << endl;
            cout << "****Please Input A Correct Operator****" << endl; // This
            is the line that gets printed even if all above // conditions are
            true
            }
            }
            cout << endl;
            cout << "The Answer To your Sum is: ";
            cout << iAnswer;
            }

            at least it is outputting the answer.. just that nasty warning asking for
            correct operator, I was told this was quite ambitious for my first program
            by my uni lecturer and was told to stick to maybe an adding calculator
            alone, but i thought i would have a go, i can see it is very simple and
            really isnt that hard to impliment. I am learning and apprecate any help i
            receive from people on usenet.


            Comment

            • John Harrison

              #7
              Re: n00b help


              "Christo" <chris@juststuf f.co.uk> wrote in message
              news:2u9iunF27j f24U1@uni-berlin.de...[color=blue]
              >
              >
              > we have not covered strings in the intro to c++ course yet at uni, just[/color]
              int,[color=blue]
              > float and char, so i havent used them, i dont want to get confused early[/color]
              on,[color=blue]
              > even though i have programmed before with vb and used php i think c++ is
              > going to be a step up for me.
              >
              > I got the program working with one minor problem... whenever i get my[/color]
              answer[color=blue]
              > it prints this line regardless if i input the correct operator (+ - * /)
              >[/color]

              It doesn't when I run it. And nor can I see any reason that it would. I
              think you must be mistaken, probably the code you have posted and the code
              you are running are not the same.

              And please drop all those silly endl

              cin >> cCmd; endl;

              This endl is doing NOTHING.

              And replace all the other endl with \n

              cout << "Help File" << endl;

              should be

              cout << "Help File\n";

              john


              Comment

              • Howard

                #8
                Re: n00b help


                "John Harrison" <john_andronicu s@hotmail.com> wrote in message
                news:2u97lfF286 6vaU1@uni-berlin.de...[color=blue]
                >[color=green]
                >>
                >> #include <iostream.h>[/color]
                >
                > #include <iostream>
                > using namespace std;
                >
                > C++ does not have a header file called <iostream.h>, any one who tells you
                > different is wrong. The cirrect header file is <iostream> without the .h.
                > Many compilers however support <iostream.h> but you should not use it
                > because it isn't proper C++. A few very old compilers do not have
                > <iostream>, they only have <iostream.h>, if that is the case for you then
                > you should get a better compiler. There are plently of free compilers
                > available which support modern C++.
                >[color=green]
                >> void main (void)[/color]
                >
                > int main()
                >
                > main always returns an int, again anyone whoe tells you different is
                > wrong.
                >[/color]
                <rant>

                Ever used CodeWarrior? In order to maintain compatibility with OS9, they
                sttill give you a void main() function when creating a project. It's not a
                matter of someone "telling you" it's right, it's just what you get when
                starting a project. Granted, it's non-standard, and ought to be changed
                (both by the user and by Metrowerks), but in the context in which it was
                used, it's correct, in that it compiles and executes without error.

                Also, in some compilers (such as CodeWarrior), iostream.h is simply a
                wrapper that does just what you've described (sort of): it includes
                <iostream>, then some other headers it needs, and then performs using
                statements as needed (depending upon certain compiler flags). It's
                perfectly valid to use, and works fine. Sure, it's less portable, but
                that's not actually always a concern of the programmer, is it?

                I know you're describing good practices, but it's not always a matter of
                someone "telling you" the wrong thing, but rather what the compiler provides
                by default. Sure I could get a new compiler, one that didn't encourage bad
                behavior, but I have a lot of thrid-party SDKs that absolutely depend upon
                my using CodeWarrior (on the Mac) or VC++ (on the PC), so that's really not
                an option, is it?

                Basically, I guess I'm just suggesting that folks ease up on the way such
                things are presented to the posters (esp. beginners). Letting them know the
                right thing to do is fine, but that should be more of an aside, not as if
                it's the main problem with their code. I know, I know: "we've gotta teach
                'em right, or they'll never learn!" I still think we oughta lighten up.
                Something more like "By the way, according to the C++ standard, main should
                return int." should be sufficient.

                "That's my opinion. I could be wrong."

                </rant>

                -Howard

                "I'm never wrong. I thought I was wrong once, but I was mistaken." -Anon


                Comment

                • Christo

                  #9
                  Re: n00b help


                  "John Harrison" <john_andronicu s@hotmail.com> wrote in message
                  news:2u9jn3F27r 3mtU1@uni-berlin.de...[color=blue]
                  >
                  > "Christo" <chris@juststuf f.co.uk> wrote in message
                  > news:2u9iunF27j f24U1@uni-berlin.de...[color=green]
                  >>
                  >>
                  >> we have not covered strings in the intro to c++ course yet at uni, just[/color]
                  > int,[color=green]
                  >> float and char, so i havent used them, i dont want to get confused early[/color]
                  > on,[color=green]
                  >> even though i have programmed before with vb and used php i think c++ is
                  >> going to be a step up for me.
                  >>
                  >> I got the program working with one minor problem... whenever i get my[/color]
                  > answer[color=green]
                  >> it prints this line regardless if i input the correct operator (+ - * /)
                  >>[/color]
                  >
                  > It doesn't when I run it. And nor can I see any reason that it would. I
                  > think you must be mistaken, probably the code you have posted and the code
                  > you are running are not the same.
                  >
                  > And please drop all those silly endl
                  >
                  > cin >> cCmd; endl;
                  >
                  > This endl is doing NOTHING.
                  >
                  > And replace all the other endl with \n
                  >
                  > cout << "Help File" << endl;
                  >
                  > should be
                  >
                  > cout << "Help File\n";
                  >
                  > john
                  >
                  >[/color]

                  ok thank you, i have just been taught that i thought endl; took you onto a
                  new line, i am not using a GUI for this just the console, at the minute i am
                  a begginner


                  Comment

                  • John Harrison

                    #10
                    Re: n00b help


                    "Christo" <chris@juststuf f.co.uk> wrote in message
                    news:2u9subF28f kn9U1@uni-berlin.de...[color=blue]
                    >
                    > "John Harrison" <john_andronicu s@hotmail.com> wrote in message
                    > news:2u9jn3F27r 3mtU1@uni-berlin.de...[color=green]
                    > >
                    > > "Christo" <chris@juststuf f.co.uk> wrote in message
                    > > news:2u9iunF27j f24U1@uni-berlin.de...[color=darkred]
                    > >>
                    > >>
                    > >> we have not covered strings in the intro to c++ course yet at uni, just[/color]
                    > > int,[color=darkred]
                    > >> float and char, so i havent used them, i dont want to get confused[/color][/color][/color]
                    early[color=blue][color=green]
                    > > on,[color=darkred]
                    > >> even though i have programmed before with vb and used php i think c++[/color][/color][/color]
                    is[color=blue][color=green][color=darkred]
                    > >> going to be a step up for me.
                    > >>
                    > >> I got the program working with one minor problem... whenever i get my[/color]
                    > > answer[color=darkred]
                    > >> it prints this line regardless if i input the correct operator (+ - *[/color][/color][/color]
                    /)[color=blue][color=green][color=darkred]
                    > >>[/color]
                    > >
                    > > It doesn't when I run it. And nor can I see any reason that it would. I
                    > > think you must be mistaken, probably the code you have posted and the[/color][/color]
                    code[color=blue][color=green]
                    > > you are running are not the same.
                    > >
                    > > And please drop all those silly endl
                    > >
                    > > cin >> cCmd; endl;
                    > >
                    > > This endl is doing NOTHING.
                    > >
                    > > And replace all the other endl with \n
                    > >
                    > > cout << "Help File" << endl;
                    > >
                    > > should be
                    > >
                    > > cout << "Help File\n";
                    > >
                    > > john
                    > >
                    > >[/color]
                    >
                    > ok thank you, i have just been taught that i thought endl; took you onto a
                    > new line, i am not using a GUI for this just the console, at the minute i[/color]
                    am[color=blue]
                    > a begginner
                    >[/color]

                    endl does take you to a new line on output (it does nothing on input) but so
                    does '\n'. The difference is that \n is easier to type and that endl as well
                    as taking you to a newline also flushes the output stream. Almost all the
                    time you don't care about flushing the output stream, maybe you don't even
                    know what it means.

                    cin >> cCmd; endl;

                    is just plain wrong, endl has no meaning on input, and if this exercise is
                    being marked you'll lose marks for that.

                    cout << "Help File" << endl;

                    is OK, but it flushes the output stream for no obviously good reason. To me
                    it just seems like one of those things that gets copied (or taught) for no
                    discernable reason but everyone ends up doing it anyway.

                    But anyway, the main thing is that you got your program working. Did you
                    sort out why that extra line was always appearing?

                    john


                    Comment

                    • Ron Natalie

                      #11
                      Re: n00b help

                      Howard wrote:
                      [color=blue]
                      > <rant>
                      >
                      > Ever used CodeWarrior? In order to maintain compatibility with OS9, they
                      > sttill give you a void main() function when creating a project. It's not a
                      > matter of someone "telling you" it's right, it's just what you get when
                      > starting a project. Granted, it's non-standard, and ought to be changed
                      > (both by the user and by Metrowerks), but in the context in which it was
                      > used, it's correct, in that it compiles and executes without error[/color]

                      <RANT> Who the hell cares. If you have to bend over to support a non-standard
                      compiler, that's fine. Howevever, we recommend the standard language
                      here. Frankly, it's got nothing to do with OS9 but everything to do
                      with CodeWarriors poor implementation. Whether nor not the OS has a
                      return value, main still needs to be an int-returning function.

                      Simmilarly for your other issues. The idea is people come here for
                      instruction. Telling them to do non-standard things just because some
                      compilers support it isn't productive.

                      Comment

                      • Christo

                        #12
                        Re: n00b help


                        "John Harrison" <john_andronicu s@hotmail.com> wrote in message
                        news:2u9u6mF291 541U1@uni-berlin.de...[color=blue]
                        >
                        > "Christo" <chris@juststuf f.co.uk> wrote in message
                        > news:2u9subF28f kn9U1@uni-berlin.de...[color=green]
                        >>
                        >> "John Harrison" <john_andronicu s@hotmail.com> wrote in message
                        >> news:2u9jn3F27r 3mtU1@uni-berlin.de...[color=darkred]
                        >> >
                        >> > "Christo" <chris@juststuf f.co.uk> wrote in message
                        >> > news:2u9iunF27j f24U1@uni-berlin.de...
                        >> >>
                        >> >>
                        >> >> we have not covered strings in the intro to c++ course yet at uni,
                        >> >> just
                        >> > int,
                        >> >> float and char, so i havent used them, i dont want to get confused[/color][/color]
                        > early[color=green][color=darkred]
                        >> > on,
                        >> >> even though i have programmed before with vb and used php i think c++[/color][/color]
                        > is[color=green][color=darkred]
                        >> >> going to be a step up for me.
                        >> >>
                        >> >> I got the program working with one minor problem... whenever i get my
                        >> > answer
                        >> >> it prints this line regardless if i input the correct operator (+ - *[/color][/color]
                        > /)[color=green][color=darkred]
                        >> >>
                        >> >
                        >> > It doesn't when I run it. And nor can I see any reason that it would. I
                        >> > think you must be mistaken, probably the code you have posted and the[/color][/color]
                        > code[color=green][color=darkred]
                        >> > you are running are not the same.
                        >> >
                        >> > And please drop all those silly endl
                        >> >
                        >> > cin >> cCmd; endl;
                        >> >
                        >> > This endl is doing NOTHING.
                        >> >
                        >> > And replace all the other endl with \n
                        >> >
                        >> > cout << "Help File" << endl;
                        >> >
                        >> > should be
                        >> >
                        >> > cout << "Help File\n";
                        >> >
                        >> > john
                        >> >
                        >> >[/color]
                        >>
                        >> ok thank you, i have just been taught that i thought endl; took you onto
                        >> a
                        >> new line, i am not using a GUI for this just the console, at the minute i[/color]
                        > am[color=green]
                        >> a begginner
                        >>[/color]
                        >
                        > endl does take you to a new line on output (it does nothing on input) but
                        > so
                        > does '\n'. The difference is that \n is easier to type and that endl as
                        > well
                        > as taking you to a newline also flushes the output stream. Almost all the
                        > time you don't care about flushing the output stream, maybe you don't even
                        > know what it means.
                        >
                        > cin >> cCmd; endl;
                        >
                        > is just plain wrong, endl has no meaning on input, and if this exercise is
                        > being marked you'll lose marks for that.
                        >
                        > cout << "Help File" << endl;
                        >
                        > is OK, but it flushes the output stream for no obviously good reason. To
                        > me
                        > it just seems like one of those things that gets copied (or taught) for no
                        > discernable reason but everyone ends up doing it anyway.
                        >
                        > But anyway, the main thing is that you got your program working. Did you
                        > sort out why that extra line was always appearing?
                        >
                        > john
                        >[/color]

                        oh damn i am stupid i didnt realize i had it on the cin

                        haha

                        not yet no, i am thining it might just be my machine, stuck it on my account
                        at uni so i check it out on friday and ask me lecturer about it.

                        Thanks for the info


                        Comment

                        • Howard

                          #13
                          Re: n00b help


                          "Ron Natalie" <ron@sensor.com > wrote in message
                          news:417fd73f$0 $28258$9a6e19ea @news.newshosti ng.com...[color=blue]
                          > Howard wrote:
                          >[color=green]
                          >> <rant>
                          >>
                          >> Ever used CodeWarrior? In order to maintain compatibility with OS9, they
                          >> sttill give you a void main() function when creating a project. It's not
                          >> a matter of someone "telling you" it's right, it's just what you get when
                          >> starting a project. Granted, it's non-standard, and ought to be changed
                          >> (both by the user and by Metrowerks), but in the context in which it was
                          >> used, it's correct, in that it compiles and executes without error[/color]
                          >
                          > <RANT> Who the hell cares. If you have to bend over to support a
                          > non-standard
                          > compiler, that's fine. Howevever, we recommend the standard language
                          > here. Frankly, it's got nothing to do with OS9 but everything to do
                          > with CodeWarriors poor implementation. Whether nor not the OS has a
                          > return value, main still needs to be an int-returning function.[/color]

                          (Just going by CWRon's response when I asked why their main returns void.)
                          [color=blue]
                          >
                          > Simmilarly for your other issues. The idea is people come here for
                          > instruction. Telling them to do non-standard things just because some
                          > compilers support it isn't productive.[/color]

                          I'm not advocating telling them to do the wrong thing, just not to
                          concentrate *so much* on those two items when responding to a post that's
                          about something else. And to respond in a kindler, gentler manner, not jump
                          on them for making a mistake that their IDE may actually have made for them.
                          That's all.

                          -Howard




                          Comment

                          Working...