find out bugs in this code

Friends it will take you 10 mins to answer but please try.
?
What does 6th warning say?
Tell me how it can be made better?

There is a lot of stuff lines i am really sorry for that!!
This website does not support long code so see it in Google docs here
main.cpp file

https://docs.google.com/uc?id=0B-e1IzT7gWcTZDY4YTExOGEtZDE4ZC00MjFlLTk1MDMtNDdjNGMxMWQ5Njhk&export=download&authkey=CJPl5-oG&hl=en_US

fraction.hpp file

https://docs.google.com/uc?id=0B-e1IzT7gWcTOTlhMTQyZmUtYjc5ZC00M2QwLWI1ZjQtZTA4YWU3ZjM5ZTFl&export=download&authkey=CPrfx7oD&hl=en_US

function.hpp file

https://docs.google.com/uc?id=0B-e1IzT7gWcTM2Q2NzNiOTUtN2E2Zi00YjIzLWFjOTktMmIxODdjMmQ3YWI3&export=download&authkey=CN6W454L&hl=en_US


warnings at compiling
1
2
3
4
5
6
7
8
9
10
11
12
13
Compiling...
main 1.cpp
e:\users\vikash chandola\documents\visual studio 2008\projects\structure\structure\function.hpp(214) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
e:\users\vikash chandola\documents\visual studio 2008\projects\structure\structure\function.hpp(215) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
e:\users\vikash chandola\documents\visual studio 2008\projects\structure\structure\function.hpp(224) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
e:\users\vikash chandola\documents\visual studio 2008\projects\structure\structure\function.hpp(225) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
e:\users\vikash chandola\documents\visual studio 2008\projects\structure\structure\function.hpp(257) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
e:\users\vikash chandola\documents\visual studio 2008\projects\structure\structure\function.hpp(237) : warning C4715: 'subtract_f' : not all control paths return a value
Linking...
Embedding manifest...
Build log was saved at "file://e:\Users\Vikash Chandola\Documents\Visual Studio 2008\Projects\structure\structure\Debug\BuildLog.htm"
structure - 0 error(s), 6 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


Thanks to all those who reply.



conversion from 'double' to 'int', possible loss of data

Well a double has a decimal fraction part (for example 3.251) and an integer does not.
A double can hold a much larger value than an integer - for example 2.126E+31
So if you try to assign a double to an integer - you will lose the decimal fraction part and if the
value is greater than an integer can hold, it will be truncated.

So that is why the compiler give that warning.


not all control paths return a value

If a function is supposed to return a value, then all the possible ways to exit that function should have a return some_value statement.
For example:

1
2
3
4
5
6
7
8
9
10
int some_function()
{
     if (some_test)
    {
          return 3;
    }

//error we need a return statement in this part of the function

}//end function 
First of all thanks for answering
you can see that there are three conditions and it is 101% sure that one of them will return. Does compiler does not understand this thing.
I have modified code to make it little better see here
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
44
45
46
// see now there is single return and and no warning.
int* subtract_f(fraction f1,fraction f2)
{
	dash_line();
	double f1n=f1.get_data("num");
	double f2n=f2.get_data("num");
	double f1d=f1.get_data("den");
	double f2d=f2.get_data("den");
	int* p=new int[2];
	if((f1n/f1d)>(f2n/f2d))
	{
		cout<<"f1 >f2\n"; 
		int n=f1n*f2d-f2n*f1d;
		int d=f1d*f2d;
		p[0]=n;
		p[1]=d;
		//dash_line();
		//return p;
	}
	if((f1n/f1d)<(f2n/f2d))
		{
			cout<<"f2 > f1\n"; 
			int n=f2n*f1d-f1n*f2d;
			int d=f1d*f2d;
			p[0]=n;
			p[1]=d;
			//dash_line();
			//return p;
		}

		if((f1n/f1d)==(f2n/f2d))
		{
			p[0]=0;
			p[1]=0;
		}
		dash_line();
		return p;

	/*if((f1n/f1d)==(f2n/f2d))
		{
			dash_line();
		return 0;
		}
*/
	//return 0;
}

Is it better .
some guys say me that why you make 3 variable in add_f function if you require only 2 then modification is done see below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int* add_f( fraction f1, fraction f2)
{
	dash_line();
	int n;
	int d;
	int f1n=f1.get_data("num");
	int f2n=f2.get_data("num");
	int f1d=f1.get_data("den");
	int f2d=f2.get_data("den");
	d=f1d*f2d;
	n=f1n*f2d+f2n*f1d;
	//int *po=new int[3];
	int* po=new int[2];
	po[0]=n;
	//po[1]=45;    //fill it just for fun
	po[1]=d;
	dash_line();
	return po;
}

Tell me any alternative of system("cls") and exit(0) I think these commands are specifically for visual C++ i want know general command so that i can run it in any compiler.
You can see more discussion on this here

http://www.codeguru.com/forum/showthread.php?t=513233
Topic archived. No new replies allowed.