| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Time engine help
I am makeing a time engine for a game. and it is not working out. first of all i will tell you how it is supposed to work. It is suppose to display a clock , that counts down,on the upper left corner.
Here is the code i got so far: Code:
#include <iostream>
using namespace std;
int main() {
int htime = 7;
int mtime = 59;
int press;
while(press != 10) {
//Clearscreen gose right here//
cout << htime << " : " << mtime << endl;
mtime --;
if (mtime == 00)
mtime == 59;
htime --;
if (mtime < 10)
cout << htime << ": 0" << mtime << endl;
if (htime == 0, mtime == 0)
cout << "press 10 to quit" << endl;
cin >> press;
if (press == 10)
return 0;
}
return 0;
}
|
|
#2
|
|||
|
|||
|
instead of this code:
if (mtime < 10) cout << htime << ": 0" << mtime << endl; if (htime == 0, mtime == 0) cout << "press 10 to quit" << endl; cin >> press; make a function that takes in as parameters htime and mtime and fixes up the string with the zeros and everything. then, you will only have the if(mtime==00) code block left. put it before the call to the string-fixing function and instead of if(mtime==00) check if(mtime==0) because integers never equal 00, only 0. also, for clearscreen, use system("cls") if you are on windows last but not least, it is good practice and almost always required to enclose code in if then else blocks with curly braces |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Time engine help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|