One line...parse error? New programmer needs help please!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • floofy
    New Member
    • Jan 2007
    • 6

    One line...parse error? New programmer needs help please!

    Hi,

    I am extremely new to programming and I'm taking a beginner's course right now. We were given a .cpp code to correct so that it will compile.

    I've already fixed a couple errors but Dev-C++ still gives me "parse" in the compiler window on this specific line:

    Code:
    for int = 0; < howmany + i++;
    I don't exactly want to post the entire code, but I'm not sure if that single line is sufficient...pa rse error is some sort of parenthesis error, I'm assuming? Can you see anything wrong with that one single line?

    Thanks in advance.
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Hey there,
    I think this is more along the lines of what you need:

    Code:
    for(int i = 0; i < howmany; i++)
    {
      // code to repeat howmany times
    }
    I hope this helps,
    Motoma

    Comment

    • floofy
      New Member
      • Jan 2007
      • 6

      #3
      Thanks for your input Motoma...but it's still not compiling for some reason!

      This is what exists in the program...I fixed all that was wrong with it before...but it's still not working.

      Code:
      #include <iostream>
      
      using namespace std;
      
      
      int main()
      {
          int howmany;      // How many values to sum.
          float sum = 0.0;  // The running sum.
      
          // Ask the user and get how many numbers to read.
          cout << "Enter how many numbers I will sum: ";
          cin >> howmany
      
          for(int i = 0; i < howmany; i++);
          {
              float value;  // The current value.
      
              // Read the ith number.
              cout << "Enter number: " ;
              cin >> value;
      
              // Increment the sum.
              sum += value;
          }
      
          // prompt the result
          cout << "The sum is: " << sum << endl;
      
          cout << "Thank you for using the summer!" << endl;
      
          return 0;  // 0 means program exited successfully.
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by floofy
        Thanks for your input Motoma...but it's still not compiling for some reason!

        This is what exists in the program...I fixed all that was wrong with it before...but it's still not working.

        #include <iostream>

        using namespace std;


        int main()
        {
        int howmany; // How many values to sum.
        float sum = 0.0; // The running sum.

        // Ask the user and get how many numbers to read.
        cout << "Enter how many numbers I will sum: ";
        cin >> howmany

        for(int i = 0; i < howmany; i++);
        {
        float value; // The current value.

        // Read the ith number.
        cout << "Enter number: " ;
        cin >> value;

        // Increment the sum.
        sum += value;
        }

        // prompt the result
        cout << "The sum is: " << sum << endl;

        cout << "Thank you for using the summer!" << endl;

        return 0; // 0 means program exited successfully.
        }
        Watch your semicolons

        cin >> howmany
        should be

        Code:
        cin >> howmany;
        for(int i = 0; i < howmany; i++);
        should probably be
        Code:
        for(int i = 0; i < howmany; i++) //without the ; at the end

        Comment

        Working...