what is the wrong in this code !

Feb 8, 2013 at 4:04pm
the compiler does not enter into inter for !!

who can tell me why ?



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
33
34
35
36
37
38
39
40
41
42
43


#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;




int fun(int x,int y);

int main()

{
	int a,b;
	cin>>a>>b;

	cout<<odai(a,b);
	cout<<endl;


	cout<<a<<b;
	cout<<endl;

	for(a;a<3;a--)
	{
		cout<<rand();
	}
	system("pause");


	return 0;

}

int fun(int x,int y)

{

	return x*y;
}
Feb 8, 2013 at 4:09pm
because a does not equal anything in the for loop. Try a = 0 because your saying if a<3 but a hasnt been assigned a value yet.
Last edited on Feb 8, 2013 at 4:11pm
Feb 8, 2013 at 5:21pm
no it's the same mistake , logical error :(
Feb 8, 2013 at 5:32pm
cout<<odai(a,b);
Does this even compile?
Feb 8, 2013 at 5:40pm
yea it's right !!
Feb 8, 2013 at 5:45pm
Well, assuming odai is a function or macro, what is it doing?
Feb 8, 2013 at 5:50pm
nothing , but your number a , b and see the result .

Feb 8, 2013 at 6:00pm
You may also want to study your for loop I get the following warning:
main.cpp||In function ‘int main()’:|
main.cpp|25|warning: statement has no effect [-Wunused-value]|


The condition clause seems to be incorrect.

Last edited on Feb 8, 2013 at 6:01pm
Feb 8, 2013 at 6:06pm
how is that !! mmmm can you tell me were is the wrong ?
Feb 8, 2013 at 6:11pm
for(a;a<3;a--)
So say you enter 2 for a, when will this loop ever end?

But the actual problem noted by the compiler is the first part, the initialization section. You either need to initialize the variable or leave that section blank.

Feb 8, 2013 at 6:18pm
my friend i already do it and put an initialize but the same mistake !! and i enter a 10 and still there a mistake !!


i don't know why !!
Feb 8, 2013 at 6:19pm
Post your corrected code.
Feb 8, 2013 at 6:30pm
no thx i know what is the wrong now ^_^ like you say i put a wrong number !!
Feb 8, 2013 at 6:36pm
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
33
#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int fun(int x,int y); // declares function fun

int main()

{
	int a,b;
	cin>>a>>b;

	cout<<odai(a,b); // uses undefined function. Maybe you meant fun() function to be called
	cout<<endl;

	cout<<a<<b; // Next applies above too
	cout<<endl; // These 2 lines can be written: cout << a << b << endl;

	for(a;a<3;a--)
	{
		cout<<rand(); // If you want to use rand() as "real" randomizer, give it a seed
	}
	system("pause");

	return 0;
}

int fun(int x,int y)
{
	return x*y;
}
Topic archived. No new replies allowed.