C4716 Error: Must return a value

I am an absolute noob to programming and i'm having some serious problems. This is a problem i have for my programming class and I'm stumped. It's saying a have to return a value to the main from a function but i just don't understand why or why it's won't compile. PLEASE help! :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//************************************
//* This program calculates the area 
//* of a rectangle.
//************************************
#include <iostream>
using namespace std;

double getLength();
double getWidth();
double getArea(double, double);
double displayData (double, double, double);

int main ()
{

	double rect_length,
           rect_width,
		   rect_area;
		   

	
	rect_length= getLength();
	rect_width= getWidth();
	
	rect_area=getArea(rect_length, rect_width);



return 0;
}

// ****************************************
//*THIS IS THE FUNCTION FOR GETTING THE 
//*RECTANGLE LENGTH
//*****************************************

double getLength(double)
{
	double length;

	cout << "Please enter the length of the rectangle: ";
	cin >> length;
	return length;

}

// ****************************************
//*THIS IS THE FUNCTION FOR GETTING THE 
//*RECTANGLE WIDTH
//*****************************************

double getWidth(double)
{
	double width;
	
	cout << "Please enter the width of the rectancle: ";
	cin >> width;
	return width;
}

// ****************************************
//* THIS FUNCTION TAKES THE RECTANGLE WIDTH
//* AND LENGTH AND MULTIPLIES THEM TO GIVE 
//* US THE RECTANGLES AREA.
//*****************************************

double getArea(double num1, double num2)
{ 
	return num1*num2;
	
}


// ****************************************
//* THIS FUNCTION ACCEPTS THE RECTANGLES 
//* LENGTH, WIDTH, AND AREA AND DIPLAYS 
//* THEM ON THE SCREEN. 
//*****************************************

double displayData(double rect_length, double rect_width, double rect_area)
{ 
	cout << "The length of the rectangle is " << rect_length << ". " << endl;
	cout << "The width of the rectangle is " << rect_width << ". " << endl;
	cout << "The area of the rectangle is " << rect_area << ". " << endl;
	
	
}




It saying "error C4716: 'displayData' : must return a value" when i try to compile it. What am i doing wrong??


Any help, or tips is greatly appreciated. Thank you!
Either declare the displayData Function as void like:
1
2
3
4
5
6
7
8
void displayData(double rect_length, double rect_width, double rect_area)
{ 
    cout << "The length of the rectangle is " << rect_length << ". " << endl;
    cout << "The width of the rectangle is " << rect_width << ". " << endl;
    cout << "The area of the rectangle is " << rect_area << ". " << endl;
    
    
}


or return a double.

1
2
3
4
5
6
7
8
double displayData(double rect_length, double rect_width, double rect_area)
{ 
    cout << "The length of the rectangle is " << rect_length << ". " << endl;
    cout << "The width of the rectangle is " << rect_width << ". " << endl;
    cout << "The area of the rectangle is " << rect_area << ". " << endl;
    
    return 0.0
}
Last edited on
Ok, tried both and neither compiled. I changed the function to void and the prototype to void


1
2
3
4
5
6
7
8
9

#include <iostream>
using namespace std;

double getLength();
double getWidth();
double getArea(double, double);
void displayData (double, double, double);





1
2
3
4
5
6
7
8
9
10


void displayData(double rect_length, double rect_width, double rect_area)
{ 
    cout << "The length of the rectangle is " << rect_length << ". " << endl;
    cout << "The width of the rectangle is " << rect_width << ". " << endl;
    cout << "The area of the rectangle is " << rect_area << ". " << endl;
    
    
}


and i changed it to return a double as well.

1
2
3
4
5
6
7
8
9

double displayData(double rect_length, double rect_width, double rect_area)
{ 
    cout << "The length of the rectangle is " << rect_length << ". " << endl;
    cout << "The width of the rectangle is " << rect_width << ". " << endl;
    cout << "The area of the rectangle is " << rect_area << ". " << endl;
    
    return 0.0
}


and the error for both of them was:

" 1>main.obj : error LNK2019: unresolved external symbol "double __cdecl getWidth(void)" (?getWidth@@YANXZ) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "double __cdecl getLength(void)" (?getLength@@YANXZ) referenced in function _main

fatal error LNK1120: 2 unresolved externals"


I am clueless. I can't figure out whats wrong.
Last edited on
Well, the functions called on main is getWidth() and getLength(). However, you've only defined the functions getLength(double) and getWidth(double). Remove those doubles and it should be fine.
Last edited on
Topic archived. No new replies allowed.