Y/N continue option

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

using namespace std;


const int SENTINEL = 'Q';  // Type this to close our loop
int main()
{
    char opLetter = ' ';
    float volume, length, width, depth, area, girth;
    
    while(opLetter != SENTINEL)
    
{
    cout << "For Area type A, or a\n"
         << "For Volume type V, or v\n"
         << "For Girth type G, or g\n"
         << "To exit this program type Q, or q"<< endl;
    cin >> opLetter;
    
//This allows you to use upper case or lower case to terminate program   
 
    if (opLetter == 'Q' || opLetter == 'q') 
{
    cout << "Program terminated" << endl;
    break;
}

    
//Asking user to input Length, Width and Depth

cout << "Please enter your length, width and depth " << endl;
cin >> length >> width >> depth;

    switch (opLetter)
{
       case 'a':
       case 'A':
area = 2 * (length*width) + 2 * (width*depth) + 2 *(length*depth);
cout << "The area is " << area << endl;
break;
       case 'v':
       case 'V':
volume = length * width * depth;
cout << "The volume is " << volume <<endl;
break;
       case 'g':
       case 'G':
girth = 2 * (width + length) + depth;
cout << "The Girth is " << girth <<endl;
break;

}


system("pause");
return 0;

}
}


After getting a little help earlier on my sentinel mess up, I finally got that to work. However, after a user completes his or her calculation, the program breaks, I want to give the user the option to continue the loop by adding an option to continue by enter y or completely stopping by pressing n. I can't get it to work no matter what I try, so again can someone shove me in the right direction? THANKS!
Move that return 0; to outside of the while loop an give it another try to ask user [Y/N]
Okay, going to try that Lendra.

Okay, that worked, so now all I've got to do is put in the other stuff. Thanks again!
Last edited on
Topic archived. No new replies allowed.