expected unqualified-id before return

I've been racking my brain for the past hour or so trying to figure this code out. The goal is to build a code that will convert pounds to kilograms upon typing the pound variable.

I keep on getting the same error: expected unqualified-id before 'return'

This is referring to the very end, where it says "return kilograms ;"

How might I go about getting rid of this error? What did I do 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
26
27
 #include<iostream>
using namespace std ;

float lbTokg ( float weightlb = 0 ) ;

int main()
{

float pounds, kilograms ;

cout << "Type wieght: \t" ;
cin >> pounds ;

kilograms = lbTokg ( pounds ) ;

cout << pounds << " lb is equal to " << kilograms << "kg " ;

return 0 ;
 }


 
float lbTokg ( float pounds ) 
 {
  float kilograms ( pounds / 2.2046 ) ;
 } 
  return kilograms ;
You have a function which should return a value, but it doesn't return anything:
1
2
3
4
float lbTokg ( float pounds ) 
{
    float kilograms ( pounds / 2.2046 ) ;
} 


and then, all alone by itself, you have this statement:
return kilograms ;

That statement needs to be moved so it is before the closing brace of the function:
1
2
3
4
5
float lbTokg ( float pounds ) 
{
    float kilograms ( pounds / 2.2046 ) ;  
    return kilograms ;
} 


Incidentally, the variable kilograms isn't needed, you could just do this:
1
2
3
4
float lbTokg ( float pounds ) 
{
    return   pounds / 2.2046 ;  
} 




Thank you! That worked perfectly.
Topic archived. No new replies allowed.