Console math problem!
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!
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.
main.o(.text+0xa5):main.cpp: undefined reference to `FindArea(unsigned short, unsigned short)''
Sorry.
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;
}
USHORT FindArea(USHORT length, USHORT width)
{
return length * width;
}
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;
}
{
return length * width;
}
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
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
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.
put
USHORT FindArea(USHORT length, USHORT width)
{
return length * width;
}
outside of your int main() function.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement