I'm trying to create a program that uses functions to determine the length, width then the final area of something but having some trouble. I run into the value being 0 in the end and not sure what I'm doing wrong! I have to assign the value 0 to the doubles as you will see but if I do not assign 0 it also doesn't run the program and states they are undeclared and it's quite frustrating I've tried everything, please point out my errors?
1) Your functions return a value, but that value is not stored anywhere. Try to store the returned value in a variable.
1 2 3
length = getLength();
width = getWidth();
area = getArea(length, width);
2) Since the functions getLength() and getWidth() ask the user for the data, you don't need to pass any arguments. The functions can be updated as:
1 2
double getLength();
double getWidth();
Similarly, the arguments for getArea() and displayData() should be limited only to values those functions use. No need to pass extra data that the function doesn't utilize.