problem with function

can someone please point me out why my second function keeps giving me a 0 when i try to use it?
Thank you guys
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
#include <iostream>
#include <math.h>
using namespace std;
//Prototype
void display(void);
int celfah(int);
int fahcel(int);

void main()
{
	//Call it 
	int choice;
	display();
	cin >> choice;

if (choice == 1 ){
	int i;
	cout << " enter number " << endl;
	cin >> i;
	cout << celfah (i);
}
else if ( choice == 2) {
	int j;
	cout << " enter number " << endl;
	cin >> j;
	cout << fahcel (j);
}
	system("pause");
}


	
		int celfah(int x){
			return ((x * 9 / 5) + 32);
		
		}
			
		int fahcel(int y){
			return ((y - 32)*(5/9));
		}
		
		void display() {
			cout << " 1- celsius to fahrenheit " << endl;
			cout << " 2- fahrentheit to celsius " << endl;
		}
Check the return types on your functions. They will definitely not be ints.
Nothing wrong with return types if he doed not need non-whole results.

Your problem is with (5/9) statement. C++ does integer division here discarding anything after decimal point. So it equals 0. To fix, force compiler to do floating division: (5.0/9)

You would have same problem with first function but order of operations and fact that you are truncating result anyway saves you here.
Topic archived. No new replies allowed.