expecting ';' before ')' token, all variables defined

Apr 2, 2010 at 3:21am
i have this utterly simple for loop:
1
2
3
4
5
6
    for(i, i<t, i++)
    {
           tmp = a + b;
           a = b;
           b = tmp;
           }

all the included variables are defined(i, t, a, b, tmp)
and yet i continue to get the same error that i don't have the expertise to interperet,
what am i doing wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;
int main()
{
    cout << "Extremely simple program for calculating the nth term of the fibonacci sequence." << endl;
    
    unsigned int a(0);
    unsigned int b(1);
    unsigned int tmp;
    unsigned int i;
    unsigned int t;
    
    cout << "number of terms: ";
    cin >> t;
    
    for(i, i<t, i++)
    {
           tmp = a + b;
           a = b;
           b = tmp;
           }

    const unsigned int nthterm = tmp;
    cout << "the #" << t << "term is " << nthterm << endl;
}
Apr 2, 2010 at 3:26am
replace for(i, i<t, i++) with for(i=0; i<t; i++)
maybe you want to check this out: http://www.cplusplus.com/doc/tutorial/control/
scroll down until you find the for loop section

Also, maybe you have to put before the end of main something like cin.get(); once or twice so that the console window doesn't close immediately and you have time to see the output.
Last edited on Apr 2, 2010 at 3:31am
Apr 2, 2010 at 3:46am
thanks so much for the quick reply, knowing me, i could have stared at that for an hour and not noticed anything wrong. and as for cin.get(); you could just use system("pause"); and get a real system pause, circular knowledge exchange is awesome :)

cheers.
Apr 2, 2010 at 4:12am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
int main()
{
    cout << "Extremely simple program for calculating the nth term of the fibonacci sequence." << endl;
    
    unsigned long a(0);
    unsigned long b(1);
    unsigned long tmp;
    unsigned long i;
    unsigned long t;
    
    cout << "number of terms: ";
    cin >> t;
    if(t==1)
    {cout << "the #1 term is 1" <<endl;system("pause");}
    else
    {
    t = t-1;
    for(i=0; i<t; i++)
    {
           tmp = a + b;
           a = b;
           b = tmp;
           }

    const unsigned long
    nthterm = tmp;
    cout << "the #" << (t+1) << " term is " << nthterm << endl;
    system("pause");
    }
}

also if you wanted to see the final code :)
Apr 2, 2010 at 4:18am
^^
Topic archived. No new replies allowed.