# Structures and Functions

Page 1 of 1

## 9 Replies - 1033 Views - Last Post: 04 November 2009 - 04:55 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=136339&amp;s=1e776da25d679e10cefa4b5f0e650e31&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Claud745

Reputation: 1
• Posts: 54
• Joined: 29-October 09

# Structures and Functions

Posted 03 November 2009 - 10:09 AM

Well I am just learning about Functions in class and still confused a little on structures. Either way I know I'm doing something wrong with my code but not sure what it is.

All I want is for the user to put in a fraction then for it to display it.

```#include <iostream>
using namespace std;

struct Fraction
{
int whole, denominator, numerator;
};

int main()
{
int enterFractionValue();
void displayFraction();
displayFraction();
return 0;
}

int enterFractionValue (Fraction f)
{
cout<<"Enter the numerator: ";
cin>> f.numerator;
cout<<"Enter the denominator: ";
cin>> f.denominator;
while(f.denominator==0)
{
cout<<"You entered a zero for the denominator, enter again:  ";
cin>>f.denominator;
}
return f.denominator;
}

void displayFraction()
{
int enterFractionValue();
}

```

I get this error
```Case projec.obj : error LNK2019: unresolved external symbol "int __cdecl enterFractionValue(void)" ([email protected]@YAHXZ) referenced in function "void __cdecl displayFraction(void)" ([email protected]@YAXXZ)

```

Is This A Good Question/Topic? 0

## Replies To: Structures and Functions

### #2 Oler1s

• D.I.C Lover

Reputation: 1397
• Posts: 3,884
• Joined: 04-June 09

## Re: Structures and Functions

Posted 03 November 2009 - 10:13 AM

Rather than telling you what the problem is, I want to see why you couldn't spot the error. You have an error message telling you exactly what the problem is. So why can't you use this error message to fix your problem?

### #3 robob686

Reputation: 7
• Posts: 44
• Joined: 24-April 09

## Re: Structures and Functions

Posted 03 November 2009 - 10:17 AM

Sorry, didn't see your post above Olerls

This post has been edited by robob686: 03 November 2009 - 10:18 AM

### #4 Claud745

Reputation: 1
• Posts: 54
• Joined: 29-October 09

## Re: Structures and Functions

Posted 03 November 2009 - 10:21 AM

I'm sorry, I just can't seem to understand the error. I'm not trying to look stupid but I feel stupid looking at it.

### #5 Oler1s

• D.I.C Lover

Reputation: 1397
• Posts: 3,884
• Joined: 04-June 09

## Re: Structures and Functions

Posted 03 November 2009 - 10:24 AM

Quote

I'm sorry, I just can't seem to understand the error. I'm not trying to look stupid but I feel stupid looking at it.
Don't feel stupid. Errors are technical pieces of information, and have to attain a bit of knowledge to understand errors. That said,

Error messages are still in English. Start by reading your error from left to right. Tell us the first piece of information you are unable to understand and why you can't understand it.

By the way, if the problem is that you can't understand the error message, you should say that! Don't just dump the error message here. Tell us where you stopped precisely.

### #6 bita

Reputation: 3
• Posts: 190
• Joined: 21-April 09

## Re: Structures and Functions

Posted 03 November 2009 - 10:25 AM

be more carfule about what you've written in you main,you can't use "int enterFractionValue();" for calling a function,omit the type (int).

and you haven't defined prototypes for your functions.

### #7 Claud745

Reputation: 1
• Posts: 54
• Joined: 29-October 09

## Re: Structures and Functions

Posted 03 November 2009 - 10:49 AM

Okay, thank you I got it now. But once again don't understand another error I'm getting.
```#include <iostream>
using namespace std;

struct Fraction
{
int whole, denominator, numerator;
};

int main()
{
int enterFractionValue();
void displayFraction();
return 0;
}

int enterFractionValue (Fraction f)
{
cout<<"Enter the numerator: ";
cin>> f.numerator;
cout<<"Enter the denominator: ";
cin>> f.denominator;
while(f.denominator==0)
{
cout<<"You entered a zero for the denominator, enter again:  ";
cin>>f.denominator;
}
return f.denominator, f.numerator;
}

void displayFraction(Fraction)
{
}
```

and my error is
error C2660: 'enterFractionValue' : function does not take 0 arguments

I just don't understand what It means by 0 arguments?

### #8 Gorian

• ninja DIC

Reputation: 153
• Posts: 1,853
• Joined: 28-June 08

## Re: Structures and Functions

Posted 03 November 2009 - 10:59 AM

Try declaring the functions out of main.

```#include <iostream>
using namespace std;

int enterFractionValue(Fraction f);
void displayFraction(Fraction);

struct Fraction
{
int whole, denominator, numerator;
};

int main()
{

return 0;
}

int enterFractionValue (Fraction f)
{
cout<<"Enter the numerator: ";
cin>> f.numerator;
cout<<"Enter the denominator: ";
cin>> f.denominator;
while(f.denominator==0)
{
cout<<"You entered a zero for the denominator, enter again:  ";
cin>>f.denominator;
}
return f.denominator, f.numerator;
}

void displayFraction(Fraction)
{
}

```

However, you can only return one thing I believe....

### #9 bita

Reputation: 3
• Posts: 190
• Joined: 21-April 09

## Re: Structures and Functions

Posted 03 November 2009 - 11:14 AM

you haven't declared your functions , use sth like this for prototypes:

```int enterFractionValue ( int );

```

declare all your functions that you want to use in your code.

### #10 gronk

Reputation: 13
• Posts: 168
• Joined: 28-October 09

## Re: Structures and Functions

Posted 04 November 2009 - 04:55 AM

Claud745, on 3 Nov, 2009 - 09:49 AM, said:

I just don't understand what It means by 0 arguments?

Have you got it yet? If not, maybe this is one of those things that needs spelling out before you see it. But I'll try one more approach.

Let's look at the function prototype (which shouldn't be in main, by the way. Function prototypes should be global unless you know what you're doing and have a very good reason for making them private):
```int enterFractionValue();

```

Look between the brackets and write down how many arguments you've told the compiler this function will take.

Now let's look at the function definition:
```int enterFractionValue (Fraction f)

```

Look between the brackets and write down how many arguments you've given the function.

Do you see any difference between the numbers you wrote down? You should, and hopefully this will cause a penny to drop in your understanding of the error message.