Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

WaterMelon34

Console math problem!

This topic is 5737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am making a simple math program that finds the area of 200 feet in length and width. Here''s the code (Tell me what''s wrong): typedef unsigned short USHORT; #include <stdio.h> #include <stdlib.h> USHORT FindArea(USHORT length, USHORT width); //function prototype int main(int argc, char *argv[]) { USHORT lengthOfYard; USHORT widthOfYard; USHORT areaOfYard; printf("\nHow wide is your yard? "); widthOfYard; printf("\nHow long is your yard? "); lengthOfYard; areaOfYard=FindArea(lengthOfYard,widthOfYard); printf("\nYour yard is "); areaOfYard; printf(" square feet\n\n"); return 0; } THANKS!

Share this post


Link to post
Share on other sites
Advertisement
Oops, I forgot to tell you what error showed up when I compiled it:

main.o(.text+0xa5):main.cpp: undefined reference to `FindArea(unsigned short, unsigned short)''

Sorry.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Uh, you neer defined the function anywhere. You declared it, but you could just change it to:

USHORT FindArea(USHORT length, USHORT width)
{
return length * width;
}

Share this post


Link to post
Share on other sites
Umm, thanks alot but now I added that and it just shows either MORE errors OR it''s the same error. Where do I put the

{
return length * width;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Uh... and you''re not using any kind of keyboard input. You can''t do that (variable

Lookup scanf().

When you want to print out a variable you have to do so like this:

printf("%d * %d = %d", input1, input2, result);

%d = integer
%s = string
%c = character(byte)
%f = float
et al

Share this post


Link to post
Share on other sites
you declared your function, you didn''t implement it though.


put
USHORT FindArea(USHORT length, USHORT width)
{
return length * width;
}

outside of your int main() function.

Share this post


Link to post
Share on other sites
Not to be bery roud, but reading a book on standard C might help. Most introductory books can teetch you what you want in a matter of 10 pages or less.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!