Why oh why did my count down effect stop working!

I have an ending message that is supposed to countdown from 3 to 1 then display an file. The count was working fine with good timing, I optimized everything but for that block I only moved the declaration int i; to the top. Even if i move it back nothing helps.

The issue: The coundown now waits for the Sleep(1000); then spits out the rest in one chunk. I want it to drop one output every second.

I am so frustrated, it worked fine yesterday!! 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
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
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
#include <cmath>
#include <stdio.h>
using namespace std;

int main ()
{
//Declare variables   
char menu, ans, coder;
string line1, line2, line3, line4, message;
ifstream welcome_message ("welcome.txt");
ifstream secret_decoder ("secret.txt");
ifstream boom_message ("boom.txt");
ofstream code;
unsigned short one=1;
int i;
double demix;
    //Output opening message image 
    //all images generated by http://www.network-science.de/ascii/
    //if the state of the stream is good output the contents of the file
    //reference http://www.cplusplus.com/doc/tutorial/files/
    while ( welcome_message.good() ){ 
          getline (welcome_message,line1);
          cout<<line1<<endl;
    }
            welcome_message.close();
            
    //if the state of the stream is good output the contents of the file
    //Output opening message image  
    while ( secret_decoder.good() ){    
          getline (secret_decoder,line2);
          cout<<line2<<endl;
    }
            secret_decoder.close();
    //Output intro message
    cout<<" This program will conceal your messages in secret "<<endl;
    cout<<" code or reveal a message you have been given"<<endl;

//Begin loop   
do{  
    //Output switch instructions
    cout<<" Enter '1' if you want to code a message "<<endl;
    cout<<" Enter '2' if you want to decode a message "<<endl;
    cout<<" ";cin>>menu;//input switch selection
    //clear residual cin crud
    cin.ignore();

            switch(menu){
                
                    case '1':{
                          //string message;
                          cout<<" What phrase do you want coded?"<<endl;
                          //input message
                          cout<<" ";getline(cin, message);
                          //open output text
                          code.open("code.txt");
                               //evaluate number of characters and for everyone increment i
                              for (size_t i=0; i < message.length(); i++){
                                 //assign each character in the string to a dummy variable
                                 coder=message.at(i);
                                 //Output the dummy variable to a file as ANSI integer multiplied by 3
                                 code<<(3*(int)coder);
                                 code<<" ";
                              }
                          //close output file
                          code.close();
                          //output coded message
                          cout<<"Okay this is your code. Write it down!"<<endl;
                          //open file with code
                          ifstream spycode("code.txt");
                                //if the state of the stream is good output the contents of the file
                                 while(spycode.good()){
                                       getline(spycode,line3);
                                       cout<<line3<<endl;
                                 }
                        //close file with code
                        spycode.close();
                        cout<<endl;
                        cout<<" Godspeed."<<endl;
                        cout<<endl;
                        break;
                    }

                    case '2':{
                        //open output text
                        code.open("code.txt");
                        //prompt for input 
                        cout<<" Enter integers to decode. Press enter after each one\n"
                        " Enter 0 when done"<<endl;
                                //begin loop
                                while(one!=0){
                                    //input coded integer
                                    cin>>one;
                                    //divide by 3 and assign to dummy variable
                                    demix=one/3;
                                    //output dummy variable as a char 
                                    code<<(char)demix;

                                }           
                        code.close();
                        cout<<"Your message is"<<endl;
                        //open the file with decoded message
                        ifstream spycode("code.txt");       
                                 //if the state of the stream is good output the contents of the file
                                while(spycode.good()){
                                       getline(spycode,line3);
                                       cout<<line3<<endl;
                                }
                       //close file with decoded message
                       spycode.close();
                       cout<<endl;
                       break;
                    }

                    default:{
                        cout<<" You're no James Bond..try again"<<endl;
                        break;
                    } 
                break;
            }
        //prompt for continuation    
        cout<<" Would you like to do more spy stuff? y/n"<<endl;
        cout<<" ";cin>>ans;
    }while(ans=='y'||ans=='Y');
        
    //output ending message 
    cout<<" This program will self destruct in.."<<endl;
    //countdown for dramatic affect
   //pause for 9\10 a sec then output a number
    
    for(i=3;i>0;i--){
        
        Sleep(1000);
        cout<<i<<"\n";}
        Sleep(1000);
    //display ending image
    //if the state of the stream is good output the contents of the file
    while ( boom_message.good() ){    
         getline (boom_message,line4);
         cout<<line4<<endl;
    }
        //close end message file
        boom_message.close();

      


  return 0;
  
}



    
It works fine here.
I see no problem.
yeah thanks. I pasted it to a new file and it works. weird.
Topic archived. No new replies allowed.