9 Replies - 687 Views - Last Post: 04 November 2009 - 04:55 AM Rate Topic: -----

#1 Claud745  Icon User is offline

  • D.I.C Head

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

Structures and Functions

Post icon  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();
	cout<< "Your number is "<<enterFractionValue()<<endl;
}



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



Is This A Good Question/Topic? 0
  • +

Replies To: Structures and Functions

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 robob686  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#4 Claud745  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#6 bita  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#7 Claud745  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • 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)
{
	cout<< "Your number is "<<enterFractionValue()<<endl;
}


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

I just don't understand what It means by 0 arguments?
Was This Post Helpful? 0
  • +
  • -

#8 Gorian  Icon User is offline

  • ninja DIC
  • member icon

Reputation: 120
  • View blog
  • Posts: 1,681
  • 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)
{
	cout<< "Your number is "<<enterFractionValue()<<endl;
}



However, you can only return one thing I believe....
Was This Post Helpful? 0
  • +
  • -

#9 bita  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#10 gronk  Icon User is offline

  • D.I.C Head

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

Re: Structures and Functions

Posted 04 November 2009 - 04:55 AM

View PostClaud745, 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1