Help with a program?

So I am building a program for an engine component analyzer, am struggling with getting the correct expected output, along with making a menu selection at the end which asks the user if they would like to do the program again. The results should be either to a. do it again, or b. terminate the program, and then invalid for everything else.
I have a majority of the code done except those few small things. Can anyone help me?

I should mention, I've been looking around all over the internet and I'm just stummped now. The program runs and I have no errors, It just isn't doing what I want it to.

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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <iostream>
#include <cmath>
using namespace std;

double PI= 3.141519;
double comp_ratio;
double vol_engine;
double vol_chamber;

int main()
{

    char menu_pic, menu_pic1, menu_pic2, doagain;
    int stroke, vol_head, q;
    double bore;
    cout << "Customize your air cooled type I VW engine"<< endl;

    do{
        cout << "Select Crankshaft        0000cc  0.0:1"    << endl;
        cout << "       a.        69  mm  stock"            << endl;
        cout << "       b.        74  mm  stroker"          << endl;
        cout << "       c.        76  mm"                   << endl;
        cout << "       d.        78  mm"                   << endl;
        cout << "       e.        82  mm"                   << endl;
        cin >> menu_pic;

        switch (menu_pic)
        {
            case 'a':
                stroke = 69;
                break;
            case 'b':
                stroke = 74;
                break;
            case 'c':
                stroke = 76;
                break;
            case 'd':
                stroke = 78;
                break;
            case 'e':
                stroke = 82;
                break;
            case 'q':
                cout << "Thanks for using Engine build v1.0" <<endl;
                break;
        }

        if (stroke == 0)
            cout << "oops!, Invalid Input" << endl;

    }while (stroke==0);

    do{
        cout << "Select Pistons           0000cc  0.0:1"  << endl;
        cout << "       a.        83  mm  underbore"      << endl;
        cout << "       b.        85.5mm  stock"          << endl;
        cout << "       c.        88  mm  overbore"       << endl;
        cout << "       d.        90.5mm"                 << endl;
        cout << "       e.        92  mm"                 << endl;
        cout << "       f.        94  mm"                 << endl;
        cin >> menu_pic1;

        switch (menu_pic1)
        {
            case 'a':
                bore = 83;
                break;
            case 'b':
                bore = 85.5;
                break;
            case 'c':
                bore = 88;
                break;
            case 'd':
                bore = 90.5;
                break;
            case 'e':
                bore = 92;
                break;
            case 'f':
                bore = 94;
                break;
            case 'q':
                cout << "Thanks for using Engine build v1.0" <<endl;
                break;
        }

        if (bore == 0)
            cout << "oops!, Invalid Input" << endl;

    }while (bore == 0);

    do{
        cout << "Select Heads             1585cc  0.0:1"    << endl;
        cout << "       a.        51  cc  stock"            << endl;
        cout << "       b.        53  cc  stage I"          << endl;
        cout << "       c.        56  cc  stage II"         << endl;
        cout << "       d.        60  cc  stage III"        << endl;
        cin >> menu_pic2;

        switch (menu_pic2)
        {
            case 'a':
                vol_head = 51;
                break;
            case 'b':
                vol_head = 53;
                break;
            case 'c':
                vol_head = 56;
                break;
            case 'd':
                vol_head = 60;
                break;
            case 'q':
                cout << "Thanks for using Engine build v1.0" <<endl;
                break;
        }

        if (vol_head==0)
            cout << "oops!, Invalid Input" << endl;

    }while (vol_head==0);


    double vol_engine = ((4*((bore/2)*(bore/2))*PI*stroke)/1000);
    double vol_chamber = ((((3/2.0)*((bore/ 2)*(bore/2))*PI)/1000)+vol_head);
    double comp_ratio =((vol_engine/4/vol_chamber)+1);


    cout <<"your engine is "
    << bore << " bore x " << stroke << " stroke" << endl;

    cout <<"your displacement is " <<vol_engine << "cc" << endl;

    cout <<"your heads have " << vol_head << "cc combustion chambers" << endl;

    cout <<"your compression ratio is " << comp_ratio << ":1" <<endl;

    if ((stroke >= 78 && bore >=88) || (bore >=90.5))
        cout <<"you will need head and case work" << endl;
    else if (bore <= 88)
        cout <<"you will need head work" << endl;
    else if (stroke >= 78)
        cout <<"you will need case work" << endl;


    if (comp_ratio >= 8.8)
        cout <<"your compression ratio is too high" << endl;
    else if (comp_ratio <= 7.8)
        cout <<"your compression ratio is too low" << endl;

    do{
        cout << "Reselect Components      "<<vol_engine<<"  "<<comp_ratio<<":1" << endl;
        cout << "       a.        yes" << endl;
        cout << "       b.        no (quit)" << endl;
        cin >> doagain;

        if (doagain == 'a')
            return 0;
        else if (doagain == 0)
            cout << "oops!, Invalid Input" <<endl;

    }while (doagain != 'b');
        cout << "Thank you for using Engine build v1.0" << endl;


    return 0;


thank you!!
Last edited on
1) initialize all variable of type int , double, char....

2) anyway can you post your incorrected result and result corrected ? ( after you appliyng -> 1) )

add line 170 }
Last edited on
I tried to run your code, but does not work as it should:

1) as the first choice allows you to choose any character and / or number;

2) the same happens in "select heads";

3) the last choice, any choice you make between 'a' and 'b', the program finishes execution
Hope this will offer you some suggestion (it's not optimized):
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include <iostream>
#include <cmath>

const double PI= 3.141519;

int askForStroke();
double askForBore();
int askForVolHead();
double calculateVolEngine(double bore, int stroke);
double calculateVolChamber(double bore, int vol_head);
double calculateCompRatio(double vol_engine, double vol_chamber);
bool askForExit(char exit_condition, char repeat_condition);

int main()
{
   do {
      int stroke = askForStroke();
      double bore = askForBore();
      int vol_head = askForVolHead();

      std::cout << "Your engine is " << bore << " bore x "
                << stroke << " stroke." << std::endl;

      double vol_engine = calculateVolEngine(bore, stroke);
      std::cout << "Your displacement is " << vol_engine
                << "cc." << std::endl;

      double vol_chamber = calculateVolChamber(bore, vol_head);
      std::cout << "Your heads have " << vol_chamber
                << "cc combustion chambers." << std::endl;

      double comp_ratio = calculateCompRatio(vol_engine, vol_chamber);
      std::cout << "Your compression ratio is " << comp_ratio << ":1" << std::endl;

      if(stroke >= 78) {
         if(bore >=88){
            std::cout << "You will need head and case work." << std::endl;
         } else { // you don't need this any more --> if (bore < 88)
            std::cout <<"You will need head work." << std::endl;
         }
      } else { // you don't need this any more --> if (stroke >= 78)
         std::cout <<"You will need case work." << std::endl;
      }

      if (comp_ratio >= 8.8)
         std::cout <<" Your compression ratio is too high." << std::endl;
      else if (comp_ratio <= 7.8)
         std::cout <<"Your compression ratio is too low." << std::endl;

      std::cout << "Reselect Components      " << vol_engine << "  "
                << comp_ratio << ":1" << std::endl;
      std::cout << "       a.        yes" << std::endl;
      std::cout << "       b.        no (quit)" << std::endl;

   } while (askForExit('b', 'a'));
   std::cout << "Thank you for using Engine build v1.0" << std::endl;

   return 0;
}

int askForStroke()
{
   int stroke {0};
   do {
      std::cout << "Customize your air cooled type I VW engine" << std::endl;
      std::cout << "Select Crankshaft        0000cc  0.0:1"    << std::endl;
      std::cout << "       a.        69  mm  stock"            << std::endl;
      std::cout << "       b.        74  mm  stroker"          << std::endl;
      std::cout << "       c.        76  mm"                   << std::endl;
      std::cout << "       d.        78  mm"                   << std::endl;
      std::cout << "       e.        82  mm"                   << std::endl;
      char menu_pic;
      std::cin >> menu_pic;

      switch (menu_pic)
      {
         case 'a':
            stroke = 69;
            break;
         case 'b':
            stroke = 74;
            break;
         case 'c':
            stroke = 76;
            break;
         case 'd':
            stroke = 78;
            break;
         case 'e':
            stroke = 82;
            break;
         case 'q':
            std::cout << "Thanks for using Engine build v1.0" << std::endl;
            break;
         default:
            std::cout << "oops!, Invalid Input" << std::endl;
            stroke = 0;
            break;
      }
   } while (stroke==0);

   return stroke;
}

double askForBore()
{
   double bore {0.0};
   do {
      std::cout << "Select Pistons           0000cc  0.0:1"  << std::endl;
      std::cout << "       a.        83  mm  underbore"      << std::endl;
      std::cout << "       b.        85.5mm  stock"          << std::endl;
      std::cout << "       c.        88  mm  overbore"       << std::endl;
      std::cout << "       d.        90.5mm"                 << std::endl;
      std::cout << "       e.        92  mm"                 << std::endl;
      std::cout << "       f.        94  mm"                 << std::endl;
      char menu_pic;
      std::cin >> menu_pic;

      switch (menu_pic)
      {
         case 'a':
            bore = 83.0;
            break;
         case 'b':
            bore = 85.5;
            break;
         case 'c':
            bore = 88.0;
            break;
         case 'd':
            bore = 90.5;
            break;
         case 'e':
            bore = 92.0;
            break;
         case 'f':
            bore = 94.0;
            break;
         case 'q':
            std::cout << "Thanks for using Engine build v1.0" << std::endl;
            break;
         default:
            std::cout << "oops!, Invalid Input" << std::endl;
            bore = 0.0;
            break;
      }
   } while (bore == 0.0);

   return bore;
}

int askForVolHead()
{
   int vol_head {0};
   do {
      std::cout << "Select Heads             1585cc  0.0:1"    << std::endl;
      std::cout << "       a.        51  cc  stock"            << std::endl;
      std::cout << "       b.        53  cc  stage I"          << std::endl;
      std::cout << "       c.        56  cc  stage II"         << std::endl;
      std::cout << "       d.        60  cc  stage III"        << std::endl;
      char menu_pic;
      std::cin >> menu_pic;

      switch (menu_pic)
      {
         case 'a':
            vol_head = 51;
            break;
         case 'b':
            vol_head = 53;
            break;
         case 'c':
            vol_head = 56;
            break;
         case 'd':
            vol_head = 60;
            break;
         case 'q':
            std::cout << "Thanks for using Engine build v1.0" << std::endl;
            break;
         default:
            std::cout << "oops!, Invalid Input" << std::endl;
            vol_head = 0;
      }
   } while (vol_head == 0);

   return vol_head;
}

double calculateVolEngine(double bore, int stroke)
{
   double vol_engine = ((4*((bore/2)*(bore/2))*PI*stroke)/1000);

   return vol_engine;
}

double calculateVolChamber(double bore, int vol_head)
{
   double vol_chamber = ((((3/2.0)*((bore/ 2)*(bore/2))*PI)/1000)+vol_head);

   return vol_chamber;
}

double calculateCompRatio(double vol_engine, double vol_chamber)
{
   double comp_ratio = ((vol_engine/4/vol_chamber)+1);

   return comp_ratio;
}

bool askForExit(char exit_condition, char repeat_condition)
{
   while(true) {
      char doagain;
      std::cin >> doagain;

      if (doagain == repeat_condition)
         return true;
      else if (doagain == exit_condition)
         return false;
      else
         std::cout << "oops!, Invalid Input" << std::endl;
   }
}


In short:
- split your code into small chunks
- empty your main()
- make every function carry out one single purpose
Topic archived. No new replies allowed.