Public Group

Archived

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

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.

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 on other sites
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 on other sites
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 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 on other sites
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 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 on other sites
What the hell...? Does this mean I delete all that crap and do that?

Share on other sites
OH!!! I understand! I forgot to give the number of the length and width aswell. I''ll try to add all the stuff you gave.

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 on other sites
Hehe, ok. Now I fixed that problem but now I can''t make the window STAY on the screen. It just opens and closes.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633731
• Total Posts
3013582
×