Returning a specific value for use

How do I return a specific value from a function in order for me to cout it in my int main?

In this case i have solved for a value sigma1 in my function but i want to use the value of sigma1 in my int main also and in other places so how would i do that?

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
 #include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>

using namespace std;

bool isInt (double value) {
    double dummy;
    return bool(modf(value, &dummy) == 0);
}

double sqr(double value) { 
	return value * value; 
}

double computeSolidity(double B1,double B2);


int main (void) {
    double B1;
    double B2;
    double I;
    double conditionB1;
    double alpha1;
    
for (;;){
     cout << "Enter Flow Entry Angle , Flow Exit Angle , and Incidence (-1 -1 -1 to exit) " << endl;
     cout << endl;
     cin >> B1 >> B2 >> I;
     cout << endl;
    if ( B1 == -1 && B2 == -1 && I == -1){
        
        break;
        }else{
            conditionB1 = (36-(0.45*B2))/(B1-B2); 
        if(B2 <= -10 || B2 >= 50 || I <= -3 || I >=3 || conditionB1 >= 1.25 || conditionB1 <= 0.75  ){
            cout << "Error ! Invalid Values Ignored " << endl; 
            }else{
                alpha1 = B1 - I;
        computeSolidity(B1,B2);
        cout << endl;
        
            cout << "Blade Entry Angle : " << alpha1 << endl;
            cout << "Solidity : " << sigma1 << endl; // how to get sigma 1?? 
            } 
    
    }
    
    
    
}   


    system("PAUSE"); return 0;

}

double computeSolidity(double B1,double B2){
    
    double LHS;
    double sigma = 0.6;
    double sigma1;
    double LHScount;
double LHScount1;  
    
     cout << "Solidity" << setw(20) << "LHS(Value)" << endl;
    cout <<"------------------------------" << endl ;
    for(sigma; sigma<2.2 ;sigma+=0.1){
    LHS = 33.5291 + (0.469188 + 0.0020961*B2)*B2 - B1 + (0.187148*B2-15.2599)*log(1/sigma)-0.677212*(pow(log(1/sigma),2));
           if(sigma==0.6){
                LHScount1 = abs(LHS);
                }else{
                    LHScount = abs(LHS);
                    if( LHScount < LHScount1){
                        LHScount1 = LHScount;
                        sigma1=sigma;
                        
                        }
                    
                    }
           
        cout << setiosflags (ios::showpoint|ios::fixed);
        
cout <<setw(5) << setprecision(1)<< sigma << setw(20) << setprecision(4) <<LHS << endl;

}
cout << "Leaving Function The chosen value is " << setprecision(1) << sigma1 << endl;

return sigma1;

}
Line 41, you call the function, but don't do anything with the result
 
    computeSolidity(B1,B2);


You could either output it directly:
 
    cout << computeSolidity(B1,B2);


or save it for later use:
 
    double sigma1 = computeSolidity(B1,B2);


duplicate thread:
http://www.cplusplus.com/forum/general/135102/

Last edited on

Yep they all work just fine Thanks alot :D !
Topic archived. No new replies allowed.