Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Jan 2007
Posts: 6
#1: Jan 19 '07
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:

Expand|Select|Wrap|Line Numbers
  1. 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...parse error is some sort of parenthesis error, I'm assuming? Can you see anything wrong with that one single line?

Thanks in advance.
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#2: Jan 19 '07

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


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

Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i < howmany; i++)
  2. {
  3.   // code to repeat howmany times
  4. }
  5.  
I hope this helps,
Motoma
Newbie
 
Join Date: Jan 2007
Posts: 6
#3: Jan 19 '07

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


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.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.     int howmany;      // How many values to sum.
  9.     float sum = 0.0;  // The running sum.
  10.  
  11.     // Ask the user and get how many numbers to read.
  12.     cout << "Enter how many numbers I will sum: ";
  13.     cin >> howmany
  14.  
  15.     for(int i = 0; i < howmany; i++);
  16.     {
  17.         float value;  // The current value.
  18.  
  19.         // Read the ith number.
  20.         cout << "Enter number: " ;
  21.         cin >> value;
  22.  
  23.         // Increment the sum.
  24.         sum += value;
  25.     }
  26.  
  27.     // prompt the result
  28.     cout << "The sum is: " << sum << endl;
  29.  
  30.     cout << "Thank you for using the summer!" << endl;
  31.  
  32.     return 0;  // 0 means program exited successfully.
  33. }
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Jan 19 '07

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


Quote:

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

Expand|Select|Wrap|Line Numbers
  1. cin >> howmany;
for(int i = 0; i < howmany; i++);
should probably be
Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i < howmany; i++) //without the ; at the end
Reply