Ok. I don't understand why this quits!

I am writing a program just for fun, that you have to know the word "pi" in order to be able to close the program while it is running. I got the code running but whenever I enter a number of loops too high, the program just quits after a certain point! Can you tell me what I am doing wrong?

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
#include <iostream>
#include <windows.h>
#include <winable.h>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void) {
    
    int x;
    int y;
    int z;
    int t;
    int loop;
    int beeps;
    int length;
    
    loop = 100;
    string stringOne;   
    cout <<"Hello, the magic word is pi";
    Sleep(1000);
    system("CLS");

cout <<"\nHow many loops would you like? (do not recommend > 100, 750 is max)  : ";
      cin >> y;
      cout <<"\nWhat would you like the beep to be?  : ";
      cin >> z;

if (z < 200){
     t = z + 100;
}
else {
     t = 100;
     }
       while (y > 750) {
             y = y - 700;}

      while (z > 99999){
             z = z / 100; }
      
      cout << "\nWhat is the magic word?  :";
      cin >> stringOne;
      
      
      beeps = y;
      
      cout << "loops left : ";
      
    for (x = 0; x < y; x++){
        if (stringOne != "pi")
      {
BlockInput (true); 
}
        
        beeps--;
        system("CLS");
        cout << "                                         " <<beeps; 
              if (beeps == 0){
                        Beep( 2000,325);
                        }
        Beep(z+loop,t);
            if (loop > 5)
{
        Sleep(loop);
            loop = loop - 2;
}
        if (t > 10)
{
        t = t - 2;
}
        
        Beep(z+loop,t); 
            if (loop < 5)
{
        Sleep(loop);
            loop = loop - 2;
}
        if (t > 10)
{
            t = t - 2;
}
       
        }    

  return 0;
}


Last edited on
Please use [c0de][/c0de] tags...(replace 0 with o) and indent.
My guess is that the program quits simply because it finished.

There's a lot of weird logic, here.
1
2
3
4
5
while (y > 750) {
	y = y - 700;}

while (z > 99999){
	z = z / 100; }
If the conditions are true, why don't you just assign the variables to their maximum allowed values?

The user doesn't get a chance to do any input inside the loop, so the only way to break it is to let it finish.

1
2
3
4
5
if (loop > 5)
{
	Sleep(loop);
	loop = loop - 2;
}
This, I simply don't understand.
"This, I simply don't understand."
Well the point of this is to pause only if loop is greater than 5, and if it is then you shorten the pause by 2, it makes the beeps more frequent; and I really don't need it. I am really not sure what you mean when you say "to their maximum allowed values, could you expand that thought?
Well the point of this is to pause only if loop is greater than 5, and if it is then you shorten the pause by 2, it makes the beeps more frequent; and I really don't need it.
Wouldn't it make more sense to use something more like Sleep((loop*loop+loop)/2) (note: this formula does almost the same as the loop, except the -2 is a -1)?

I am really not sure what you mean when you say "to their maximum allowed values, could you expand that thought?
This:
1
2
3
4
if (y>750)
    y=750;
if (z>99999)
    z=99999;
Thank you! The Sleep formula is quite helpful! And yes that would make a lot more sense to set them to their maximum allowed values.
Topic archived. No new replies allowed.