Pulling a value from vector every 10 seconds

So this is my program currently. It not finished but I figured out I would put it up here to see if I could get some help. I used for loops to get the general idea but I really need the program to pull the first value from each array and display the messages and then x amount of time later pull the second value and display those messages until it has pulled all six values from the vector.

I'm printing out the vectors just to see the values while i'm testing the program but eventually i will get rid of that part.

Thank you for the help

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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
  #include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;

int main(void)
{
    vector<double> temp(0);
    double temperature;
    int i;
	int j;
	int k;
	int l;
	int m;
    int n;
    int p;
    char exitProgram;


    ifstream ipFile1; /* Defining an input file */

    ipFile1.open ("temperatures.txt");  /* Opening the file */
	if (ipFile1.is_open())    /* Ensuring that the file is open */
	{
		/* Reading the contents of the file */
		while ( ipFile1 >> temperature ) /* Reads the string from the input file into the string variable tempString */
		{
			temp.push_back(temperature);
		}
		cout << endl;

		ipFile1.close(); /* Closing the file since we are done */
	}

	for(i=0;i<temp.size();i++)
	{
		cout << temp.at(i) << endl;
	} /* End for loop */


    vector<double> HCNppm(0);
    double HCN;

    ifstream ipFile2; /* Defining an input file */

    ipFile2.open ("HCNppm.txt");  /* Opening the file */
	if (ipFile2.is_open())    /* Ensuring that the file is open */
	{
		/* Reading the contents of the file */
		while ( ipFile2 >> HCN ) /* Reads the string from the input file into the string variable tempString */
		{
			HCNppm.push_back(HCN);
		}
		cout << endl;

		ipFile2.close(); /* Closing the file since we are done */
	}

	for(j=0;j<HCNppm.size();j++)
	{
		cout << HCNppm.at(j) << endl;

	} /* End for loop */


vector<double> COppm(0);
    double CO;

    ifstream ipFile3; /* Defining an input file */

    ipFile3.open ("COppm.txt");  /* Opening the file */
	if (ipFile3.is_open())    /* Ensuring that the file is open */
	{
		while ( ipFile3 >> CO ) /* Reads the string from the input file into the string variable tempString */
		{
			// cout << temperature << " ";
			COppm.push_back(CO);
		}
		cout << endl;

		ipFile3.close(); /* Closing the file since we are done */
	}

	for(k=0;k<COppm.size();k++)
	{
		cout << COppm.at(k) << endl;
	} /* End for loop */


vector<double> COinMask(0);
    double COin;

    ifstream ipFile4; /* Defining an input file */

    ipFile4.open ("COinMask.txt");  /* Opening the file */
	if (ipFile4.is_open())    /* Ensuring that the file is open */
	{
		while ( ipFile4 >> COin ) /* Reads the string from the input file into the string variable tempString */
		{
			// cout << temperature << " ";
			COinMask.push_back(COin);
		}
		cout << endl;

		ipFile4.close(); /* Closing the file since we are done */
	}

	for(l=0;l<COinMask.size();l++)
	{
		cout << COinMask.at(l) << endl;
	} /* End for loop */


vector<double> HCNinMask(0);
    double HCNin;

    ifstream ipFile5; /* Defining an input file */

    ipFile5.open ("HCNinMask.txt");  /* Opening the file */
	if (ipFile5.is_open())    /* Ensuring that the file is open */
	{
		/* Reading the contents of the file */
		while ( ipFile5 >> HCNin ) /* Reads the string from the input file into the string variable tempString */
		{
			HCNinMask.push_back(HCNin);
		}
		cout << endl;

		ipFile5.close(); /* Closing the file since we are done */
	}

	for(m=0;m<HCNinMask.size();m++)
	{
		cout << HCNinMask.at(m) << endl;
	} /* End for loop */


vector<double> internaltemperature(0);
    double intemp;

    ifstream ipFile6; /* Defining an input file */

    ipFile6.open ("internaltemp.txt");  /* Opening the file */
	if (ipFile6.is_open())    /* Ensuring that the file is open */
	{
		/* Reading the contents of the file */
		while ( ipFile6 >> intemp ) /* Reads the string from the input file into the string variable tempString */
		{
			internaltemperature.push_back(intemp);
		}
		cout << endl;

		ipFile6.close(); /* Closing the file since we are done */
	}

	for(n=0;n<internaltemperature.size();n++)
	{
		cout << internaltemperature.at(n) << endl;
	} /* End for loop */


cout << "Conditions from the sensors placed on firefighters gear will be read in every 10 seconds,";
cout << endl << "along with a message describing the meaning of those readings.";
cout << endl;
cout << "To exit program press 'x'";
cin >> exitProgram;

i=0;
j=0;
k=0;
l=0;
m=0;
n=0;

for (i=0 ; i<=6 ; i++)
{
	if (temp.at(i)<= 200)
	{
		cout << "Fire still in growth stage producing large amounts of smoke produced";
		cout << endl << "No major issues" << endl;
	}
	else if (temp.at(i)>200 && temp.at(i)<400)
	{
		cout << "Rising temperatures, getting closer to the seed of the fire";
		cout << endl << "Conditons are getting increasing more dangerous.";
		cout << "Move foreward to fire attack or begine to plan an evacuation ";
		cout << "for the firefighters working inside" << endl;
	}
	else if (temp.at(i)>=400 && temp.at(i)<850)
	{
		cout << "WARNING: extremely high temperatures" << endl;
		cout << "Imediately get water onto the fire or make way out of the building";
		cout << endl << "Approaching flashover conditions" << endl;
	}
	else
	{
		cout << "WARNING!! WARNING!!" << endl;
		cout << "Flashover conditions, evcuate the building, " << endl;
		cout << "move to exterior attack." << endl ;
	}
	cout << endl;
} //End for (i)

for (j=0 ; j<=6 ; j++)
{
	if (HCNppm.at(j)<=100)
	{
		cout << "Low levels of HCN in the enviornemt, no real issue" << endl;
	}
	else if (HCNppm.at(j)>100 && HCNppm.at(j)<=200)
	{
		cout << "Increased HCN levels, direct exposeure will result to death in 10 minutes";
		cout << endl;
	}
	else if (HCNppm.at(j)>200 && HCNppm.at(j)<=1000)
	{
		cout << "WARNING: high values of HCN will cause death after 5 min of exposure";
		cout << endl << "Monitor levels inside of mask" << endl;
	}
	else
	{
		cout << "WARNING!! WARNING!!" << endl;
		cout << "Extremely high levels of HCN, 1 min of direct exposure will result in death";
		cout << endl;
	}
} // end for (j)
for (k=0 ; k<=6 ; j++)
{

} // end for (k)
for (l=0 ; l<=6 ; l++)
{

} //end for (l)
for (m=0 ; m<=6 ; m++)
{

} // end for (m)
for (n=0 ; n<=6 ; n++)
{

} // end for (n)
	return 0;

} /* End main */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <chrono>
#include <thread>
#include <string>

int main()
{
    const std::string messages[] { "To", "be,", "or", "not", "to", "be:", "that", "is", "the", "question" };

    for( const std::string& msg : messages )
    {
        std::cout << msg << ' ' << std::flush ;

        using namespace std::literals ;
        // http://en.cppreference.com/w/cpp/thread/sleep_for
        // http://en.cppreference.com/w/cpp/chrono/operator%22%22s
        std::this_thread::sleep_for( 1s ) ; // introduce a delay of one second
    }
}
I'm a little confused. Where exactly would I put this in my code. Would i only have to do it once or would i have to do it to replace every for loop that i already have in the code.
Place it in the loop / loops where you want the delay.
So I tried to run this code to see how it work and I got multiple errors saying that the i need the 2011 version of c++ and that the compiler that i"m using does not support that. Is there any other way to do it. Or what do i need to do to get it to work with the compiler that im using.
And i'm also getting runtime error after I run the whole program. It will stop after going through the very first for loop for the temp vector and i'm not sure why it wont run through all of the for loops.
> Or what do i need to do to get it to work with the compiler that im using.

There was no standard C++ way to do that before C++11.

Posix: https://www.freebsd.org/cgi/man.cgi?query=sleep&apropos=0&sektion=3&manpath=FreeBSD+10.2-RELEASE&arch=default&format=html

Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx
Alright so I updated the compiler and can now do the c++11. But when I try to compile the small program that you sent just to see how it works im still getting errors that im not sure how to fix before i try to change it to work with my program
I just tried it with just the Sleep function and the delay worked but I need it to pull the first value form each vector after 10 seconds and the the second value from the vector after another 20 seconds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <chrono>
#include <thread>
#include <string>
#include <vector>

int main()
{
    const std::vector<std::string> messageS { "To", "be,", "or", "not", "to", "be:", "that", "is", "the", "question" };

    for( size_t i = 0; i < messageS.size(); ++i )
    {
        std::cout << messageS[i] << ' ' << std::flush ;

        using namespace std::literals ;
        // http://en.cppreference.com/w/cpp/thread/sleep_for
        // http://en.cppreference.com/w/cpp/chrono/operator%22%22s
        std::this_thread::sleep_for( (i +1) * 10s ) ; // introduce a delay of (i + 1) * 10 seconds
    }
}
Last edited on
Topic archived. No new replies allowed.