Why is this not returning recT ?

why is the last function not returning result? (recT)

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
90
91
92
93
94
95


        #include <iostream>
#include <stdlib.h>
using namespace std;
#include <string>
#include "main.h"

void initMenu();
void mDecision(int);
double areaC(double);
double sQuare(double);
const double pi = 3.14;
int choice;
double recT(double, double);

int main() 
{
        initMenu();
	cin >> choice;
	mDecision(choice);
	

	system("pause");

	return 0;
}
void initMenu()
{
	cout << "Enter option: " << endl;
	cout << "1. Circle: " << endl;
	cout << "2. Square: " << endl;
	cout << "3. Rectangle: " << endl;
	cout << "4. Triangle: " << endl;





}
void mDecision(int)
{

	double t;
	double r, s, h, w, a;
	switch (choice) 
	{
	case 1:
		cout << "Enter the radius" << endl;
		cin >> r;
		areaC(r);
		break;
	case 2:
		cout << "Enter the side of the square" << endl;
		cin >> s;
		sQuare(s);
		break;
	case 3:
		cout << "Enter the width " << endl;
		cin >> w;
		cout << "Enter the hiegth " << endl;
		cin >> h;
		recT(h, w);
		break;
	case 4:
		cout << "Enter the " << endl;
		cin >> r;
		
		break;
	default:
		cout << "Wrong choice" << endl;
	}
}

double areaC(double r)
{
	double result = pi * r * r;
	cout << "The area of a circle is: " << result << endl;

	return result;
}

double sQuare(double s)
{
	double sResult = s * 4;
	cout << "The area of the square is " << sResult << endl;

	return 0.0;
}

double recT(double h, double w)
{
	double rResult = (h * 2) + (w * 2);
	return 0.0;
}


works fine with square and circle, however i cant get the recT fxn to return
Last edited on
Return what?

Both sQuare and recT do return 0.0 but you do ignore the returned value (lines 56 and 63).

Your areaC does return the computed area, but you do ignore that too (on line 51).
in recT it does not return the result of h * 2 + w * 2.
in case 3
Look at your function (on lines 91-95).
* On line 93 it does compute something and stores the resulting value into local variable rResult.
* On line 94 the function does return a value. What value is that?


Now look at line 63. On that you do call recT(). A function that returns a value.
What do you do with the value? Nothing. You don't store it or use it.
You cannot complain about the function not returning anything when your code does not care what it returns.

Perhaps reading this helps: http://www.cplusplus.com/doc/tutorial/functions/
lol thanks, im taking a class and the online course moves so fast
Topic archived. No new replies allowed.