Want user to be able to have option to rerun program before exiting

After I run through the program one time I want to be able to ask the user if they want to rerun the program again. Not quite sure how to make it happen. What I have now is not working correctly

Thanks in advance

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
#include <iostream>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;
// Variable Meanings
// Pipe radius                         = a = 0.05m
//Radius of pip + insulation           = b= (a+insulation thickness)
//Pipe Length                          = L= 100m
//Pipe Temperature                     =Ta= 150 C
//Insulation conductivity              =k=0.1watt/(m C)
//Convection constant                  =F=3.0watt/(m C)
//Pipe insulation cost                 =Cvol=$325/m cubed
//Insulation installation cost         =CL=$1.50/m
//Cost of heat                         =Cstheat= 1.11x10^-9

int main()
{
    float i, thick_increment, start, end, start_temp, end_temp, temp_increment, a, b, L, Ta, k, F, Cvol, CL, Cstheat, tenneg9, dQ, Q3, c, d, e, f, g, h, j,CI, CI_1, CI_2, tenpos8, one5sev, cf, CF, fuel_savings, tair, dQ_1, dQ_2, CF_1, CF_2, Q3_1, Q3_2, fuel_savings1, fuel_savings2, rerun, y;
    
    float temp[3];
    
    do {
        
    cout<<"Enter the starting thickness""\n";
    cin>>start;
    cout<<"enter the end thickness""\n";
    cin>>end;
    cout<<"Enter the thickness increment""\n";
    cin>>thick_increment;
    cout<<"Enter the starting temperature""\n";
    cin>>start_temp;
    cout<<"Enter the ending temperature ""\n";
    cin>>end_temp;
    cout<<"Enter the temperature  increment size""\n";
    cin>>temp_increment;
    
    cout<<setw(10)<<"Thickness"<<setw(15)<<"CI"<<setw(25)<<"CF"<<setw(35)<<"fuel_savings @ "<<start_temp<<setw(25)<<"fuel_savings @ "<<start_temp+temp_increment<<setw(25)<<"fuel_savings @ "<<end_temp<<endl;
    
    for (i=start; i<=end; i=i+thick_increment)
    {  a=.05;
    b= a+i;
    L=100;
    Ta=150;
    k=.1;
    F=3;
    Cvol=325;
    CL=1.5;
    tenneg9= pow(10, -9);
    Cstheat=1.11*tenneg9;
    CI_1=(b*b-a*a)*(L)*(Cvol);
    CI_2=L*CL;
    CI=CI_1+CI_2;
        
        for (tair=start_temp; tair<=end_temp; tair=tair+temp_increment)
        c=b/a;
        d=b*F;
        e=d/k;
        f=log(c);
        g=(e*f)+1;
        h=c/g;
        j=1-h;
        dQ=Q3*j;
        dQ_1=Q3_1*j;
        dQ_2=Q3_2*j;
        Q3_1=2*3.14*a*F*(Ta-0)*L;
        Q3_2=2*3.14*a*F*(Ta-10)*L;
        Q3=2*3.14*a*F*(Ta-(-10))*L;
        tenpos8= pow(10, 8);
        one5sev=1.578*tenpos8;
        cf=dQ*Cstheat;
        CF=dQ*one5sev*Cstheat;
        CF_1=dQ_1*one5sev*Cstheat;
        CF_2=dQ_2*one5sev*Cstheat;
        fuel_savings=CF-CI;
        fuel_savings1=CF_1-CI;
        fuel_savings2=CF_2-CI;
        
         cout<<i<<setw(25)<<CI<<setw(25)<<CF<<setw(25)<<fuel_savings<<setw(25)<<fuel_savings1<<setw(25)<<fuel_savings2<<endl;
        
        
    }
    cout<<"Do you want to run this program again? (y/n)""\n";
        cin>>rerun;
     } while (rerun=='y' ||'Y');
    return 0;
}
The problem is line 86: That's not a valid comparison. C++ does not support an implied left hard side in a comparison. The second term of the comparison ('Y') will always be true.

Rewrite that as:
 
} while (rerun == 'y' || rerun == 'Y');

Also you've declared rerun to be a float variable - looks like you meant it to be a char if you're expecting the user to input a single y or n.
@wildblue - Good catch.
Topic archived. No new replies allowed.