Holding the program open

I've got the majority of the code down, I' am just running into the issue of the program window not staying open after I press enter to continue.

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

using namespace std;
int main ()
{
    
    char fallen;
    int user;
    int result;
    
    cout << "Enter a letter \n";
    cout << "\n";
   
    cin >> fallen;
    cout<< "\n";
    cout<< "\n";
    
   switch (fallen)
   {
          case 'A':
          case 'a':
          cout<< "You are amazing. \n";
          cout << "\n";
          cout << "\n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
          if (user >= 90 <= 100)
          {
                   result = (100 - user);
                   cout<< "\n";
                   cout<< " You are " << result << " points away from a perfect score. \n";
                   cout<< "\n";
                   }
          if (user >= 101 <= 89)
          {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   
          break;
          
          case 'B':
          case 'b':
          cout<< "You did good. \n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
          if (user >= 89 <= 80)
          {
                   result = (90 - user);
                   cout<< "\n";
                   cout<< " You are " << result << " points away from an 'A' score. \n";
                   cout<< "\n";
                   }
          if (user >= 90 <= 79)
          {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
          break;
          
          case 'C':
          case 'c':
          cout<< "You did ok, but there is room for improvement. \n";
          cout << "What exact percent did you get on your test? \n";
          cin.ignore ();
          cout << "\n";
          cin >> user;
          
          if (user >= 79 <= 70)
          {
                   result = (80 - user);
                   cout<< "\n";
                   cout<< " You are " << result << " points away from a perfect score. \n";
                   cout<< "\n";
                   }
          if (user >= 80 <= 69)
          {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
          break;
          
          case 'D':
          case 'd':
          cout<< "You have to do better, you have brought shame to your family. \n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
          if (user >= 69 <= 60)
          {
                   result = (70 - user);
                   cout<< "\n";
                   cout<< " You are " << result << " points away from a perfect score. \n";
                   cout<< "\n";
                   }
          if (user >= 70 <= 59)
          {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
          break;
          
          
          case 'F':
          case 'f':
          cout<< "You are a failure and a complete fool. \n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
          if (user >= 59 <= 50)
          {
                   result = (60 - user);
                   cout<< "\n";
                   cout<< " You are " << result << " points away from a perfect score. \n";
                   cout<< "\n";
                   }
          if (user >= 60 <= 49)
          {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
          break;
             
          
          default:
                  cout<< "You freakin idiot, thats not an answer. \n";
                  cout<< "\n";
                  
          
          }
          cin.ignore ();
          cin.ignore ();
          cin.get ();
          cin.get ();
           system("pause");
          }
          }
          }
          }
          }
          }
Are you honestly saying this code compiles? There should be quite a few compiling errors...

a) I have no idea where all those }'s are coming from in the last few lines.
b) Your if's are wrong. You can't double up on arguments like that. The proper way is "if (y > x && y < z)".
c) Your main isn't returning a value.
d) There is a whole Sticky on how to keep your console open at the end. Easiest way? Add this as your final two lines of main() (only followed by "return 0;")
1
2
int i;
cin >> i;

e) Some of your if's don't close ('}'). Check 38, and many others.
Last edited on
@Gaminic: You're correct about b, but it does compile; when I tried it it just gave me a warning. Also, I'm pretty sure you don't need to return a value in int main() anymore. An easier way to keep the console open is cin.getline(); instead of creating a variable. Please correct me if I'm wrong about any of that.
I see nothing stopping B from being syntactically correct, but I'd highly doubt it would work in the way that's expected. :)

As for E... technically, those ifs do close. Where do you think all those }'s that you mentioned in A are coming from?

-Albatross
I've got most of it reworked, but for some reason, I cant now get the else if statement to appear if that statement is true. Any ideas?




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

#include <iostream>
#include <cstdlib>

using namespace std;
int main ()
{
    
    char fallen;
    int user;
    int result;
    
    cout << "Enter a letter \n";
    cout << "\n";
   
    cin >> fallen;
    cout<< "\n";
    cout<< "\n";
    
   switch (fallen)
   {
          case 'A':
          case 'a':
          cout<< "You are amazing. \n";
          cout << "\n";
          cout << "\n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          
          cin >> user;
          
              if (user >= 90 && user <= 100)
          {
                   result = (100 - user);
                   cout<< "\n";
                   cout<< " You are " << result << " points away from a perfect score. \n";
                   cout<< "\n";
                   }
              
              else if (user >= 101 && user <= 89)
         {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
                   
          break;
          
          case 'B':
          case 'b':
          cout<< "You did good. \n";
          cout<< "\n";
          cout<< "\n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
              if (user >= 89 && user <= 80)
          {
                   result = (90 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from an 'A'. \n";
                   cout<< "\n";
                   }
                   
                   else  (user >= 90 && user <= 79);
          {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
          
          case 'C':
          case 'c':
          cout<< "You did ok, but there is room for improvement. \n";
          cout<< "\n";
          cout<< "\n";
          cout << "What exact percent did you get on your test? \n";
          cin.ignore ();
          cout << "\n";
          cin >> user;
          
              if (user >= 79 && user <= 70)
              {
                   result = (80 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from a 'B'. \n";
                   cout<< "\n";
                   
                   }
                    else if  (user >= 80 && user <= 69)
                    {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
          
          case 'D':
          case 'd':
          cout<< "You have to do better, you have brought shame to your family. \n";
          cout<< "\n";
          cout<< "\n";
          
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
              if (user >= 69 && user <= 60)
              {
                   result = (70 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from a 'C'. \n";
                   cout<< "\n";
                   }
                  
                  else  (user >= 70 && user <= 59);
                  {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
          
          
          case 'F':
          case 'f':
          cout<< "You are a failure and a complete fool. \n";
          cout<< "\n";
          cout<< "\n";
          
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
              if (user >= 59 && user <= 50)
              {
                   result = (60 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from a 'D'. \n";
                   cout<< "\n";
                   }
                   
                   else if  (user >= 60 && user <= 49)
                   {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
             
          
          default:
                  cout<< "You freakin idiot, thats not an answer. \n";
                  cout<< "\n";
                  
          
          }
          
                   
                   
          cin.ignore ();
          cin.ignore ();
          cin.get ();
          cin.get ();
           system("pause");
          }
Last edited on
The conditions in your if statements will always be false. No number is less than or equal to a number and greater than or equal to a bigger number. Switch the logical operators.
Last edited on
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
#include <iostream>
#include <cstdlib>

using namespace std;
int main ()
{
    
    char fallen;
    int user;
    int result;
    
    cout << "Enter a letter \n";
    cout << "\n";
   
    cin >> fallen;
    cout<< "\n";
    cout<< "\n";
    
   switch (fallen)
   {
          case 'A':
          case 'a':
          cout<< "You are amazing. \n";
          cout << "\n";
          cout << "\n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          
          cin >> user;
          
              if (user >= 90 && user <= 100)
          {
                   result = (100 - user);
                   cout<< "\n";
                   cout<< " You are " << result << " points away from a perfect score. \n";
                   cout<< "\n";
                   }
              
              else 
         {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
                   
          break;
          
          case 'B':
          case 'b':
          cout<< "You did good. \n";
          cout<< "\n";
          cout<< "\n";
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
              if (user <= 89 && user >= 80)
          {
                   result = (90 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from an 'A'. \n";
                   cout<< "\n";
                   }
                   
                   else  
          {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
          
          case 'C':
          case 'c':
          cout<< "You did ok, but there is room for improvement. \n";
          cout<< "\n";
          cout<< "\n";
          cout << "What exact percent did you get on your test? \n";
          cin.ignore ();
          cout << "\n";
          cin >> user;
          
              if (user <= 79 && user >= 70)
              {
                   result = (80 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from a 'B'. \n";
                   cout<< "\n";
                   
                   }
                    else   
                    {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
          
          case 'D':
          case 'd':
          cout<< "You have to do better, you have brought shame to your family. \n";
          cout<< "\n";
          cout<< "\n";
          
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
              if (user <= 69 && user >= 60)
              {
                   result = (70 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from a 'C'. \n";
                   cout<< "\n";
                   }
                  
                  else  
                  {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
          
          
          case 'F':
          case 'f':
          cout<< "You are a failure and a complete fool. \n";
          cout<< "\n";
          cout<< "\n";
          
          cout << "What exact percent did you get on your test? \n";
          cout << "\n";
          cin.ignore ();
          cin >> user;
          
              if (user <= 59 && user >= 50)
              {
                   result = (60 - user);
                   cout<< "\n";
                   cout<< " You were " << result << " points away from a 'D'. \n";
                   cout<< "\n";
                   }
                   
                   else   
                   {
                   cout<< "\n";
                   cout<< "I' am sorry that is not with in your grade range. \n";
                   cout<< "\n";
                   }
          break;
             
          
          default:
                  cout<< "You freakin idiot, thats not an answer. \n";
                  cout<< "\n";
                  
          
          }
          
                   
                   
          cin.ignore ();
          cin.ignore ();
          cin.get ();
          cin.get ();
           system("pause");
          }



changed else ifs to elses... changed your grade range
Last edited on
closed account (zb0S216C)
Gaminic wrote:
Your main isn't returning a value. (sic)

The compiler is kind enough to return zero for you, but the compiler draws the line at functions other than main( ).

Keeping you console open could be achieved like this:

 
std::cin.ignore( std::numeric_limits< std::streamsize >::max( ), '\n' );


It looks complex at a glance but it's simple to understand. Alternatively, you could use std::cin.get( ).

Wazzak
Topic archived. No new replies allowed.