Two compiling errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lizaww
    New Member
    • Nov 2008
    • 6

    Two compiling errors

    Can you please tell me what i am missing? I get two errors when i compile.

    Code:
     
    #include
    <iostream> using namespace std;
    int main()
    {
    double num_one, num_two, num_three, num_four, num_five, num_six, num_seven, num_eight, sum, product, average;char ans ;
     
    cout << "Please enter eight numbers: "<< endl; 
    cin >> num_one >> num_two >> num_three >> num_four>> num_five >> num_six >> num_seven >> num_eight;
     
    cout << "The sum of the numbers is: " << endl;sum =num_one + num_two + num_three + num_four + num_five+ num_six + num_seven + num_eight;
    cout << sum << endl;
     
    cout << "The product of the numbers is: " << endl;
     
    product = num_one * num_two * num_three * num_four * num_five * num_six * num_seven * num_eight;cout << product << endl;
     
    cout << "The average of the numbers is: " << endl;
    average = (num_one + num_two + num_three + num_four + num_five + num_six + num_seven + num_eight)/8;
    cout << average << endl;
    return 0
    }
  • vmpstr
    New Member
    • Nov 2008
    • 63

    #2
    You are missing a semicolon after return 0. Also, for the future: it would be extremely helpful if you, aside from posting your code, also post the error you get.

    Typically, we are much better at understanding the error message than we are at just skimming the code and figuring out what's wrong.

    good luck! :D

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Also, your using namespace std is on the same line as #include<iostre am>.

      All those lines starting with # are preprocessor directives. Everything on that line must apply to that directive.

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        Also you need to pause the output screen so you can read the output by, for example, writing system("pause") ;before return 0;...... although I`m not sure the experts would agree with this method

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          Originally posted by whodgson
          Also you need to pause the output screen so you can read the output by, for example, writing system("pause") ;before return 0;...... although I`m not sure the experts would agree with this method
          It really depends on several things. When I am using a command line compiler like g++, I don't need the system("pause") command at the end, since I can just view the output in the command prompt after the program runs. When I use the IDE Dev C++, I need to use that line, because otherwise the window disappears (I've been told running in the non-Debugging mode fixes this, but I've done it in non-Debug mode, and it still doesn't work).

          Regardless, don't just blindly put in system("pause") at the end of your program. Doing so means it will only work in environments where "pause" is a valid shell command (as far as I know, Windows has it, Linux does not). There are other ways to simulate the same effect without forcing an OS dependency, such as manually using cin.get() to force the user to type in a character before the program terminates.

          The bottom line is this: you don't always need to pause the screen, and when you do, be aware that your method may limit the portability of your code.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            If may also limit the usability of your code, for instance if the program is meant to be used in an automated process (an overnight build say) then pausing at the end waiting for user input is the last thing you want to be doing.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              w.r.t. the original problem: what would the OP have done if, say, hundred numbers, or thousand of them, had to be processed?

              kind regards,

              Jos

              Comment

              Working...