Hey, I am a 14 year old beginner programmer and while learning about C++, I decided I'll make a program where you have to input:
the hours the program has to count up to,
the minutes the program has to count up to,
the seconds it has to count up to
and finally, you have to write yes to start the while(){ loop.
However, when I type in my hrs, mins, secs and type in yes, the program doesn't do anything. It doesn't even close, it's as if it was at the end and was paused. Nothing comes up, there are no runtime errors and there are no bugs when I compile my code.
This is my code so far:
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
|
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int second = 60; //Maximum
int minute = 60 * second; //Maximum
int hour = 24 * minute; //Maximum
int hd = 0; //How many hours passed
int md = 0; //How many minutes passed
int sd = 0; //How many seconds passed
int x = 0; //Current hour
int y = 0; //Current minute
int z = 0; //Current second
int a = -1; //Memory
int b = -1; //Memory
int c = -1; //Memory
int dh = 1; //Target hours reached
int dm = 1; //Target minutes reached
int ds = 1; //Target seconds reached
//string reason; //declaring reason
string yes; //declaring starting string
int main(){
// string reason = " "; //reason set to nothing
string yes = " "; //starting up string set to nothing
cout << " " << endl;
cout << "Welcome to Milan's count up program." << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Enter the number of hours to count up to: " << endl;
cin >> a;
cout << "You have chosen " << a << " hours." << endl;
cout << "Enter the number of minutes to count up to: " << endl;
cin >> b;
cout << "You have chosen " << b << " minutes." << endl;
cout << "Enter the number of sec to count up to: " << endl;
cin >> c;
cout << "You have chosen " << c << " seconds." << endl;
// cout << "Enter the message you want to be sent when the time is met" << endl;
// cin >> reason;
cout << "Are you ready?" << endl;
cin >> yes;
while(yes == "yes"){
if(a>0){
int y = 0;
x++;
if(x == a){
int hd = 1;
cout << a << "hours have past." << endl;
}
}
else{
if(hd == 1){
if(dh == 1){
cout << a << "hours have past." << endl;
int dh = 0;
}
}
}
if(b>0){
int z = 0;
y++;
if(hd == 1){
if(y == a){
int md = 1;
cout << b << "minutes have past." << endl;
}
else{
if(hd == 1){
if(dm == 1){
cout << b << "minutes have past." << endl;
int dm = 0;
}
}
}
}
}
if(c>0){
Sleep(1000);
z++;
if(md == 1){
if(z == a){
int sd = 1;
cout << c << "seconds have past." << endl;
string yes = "done";
}
}
}
}
// cout << reason << endl;
Sleep(5000);
cout << "Thank you for using Milan's count up program !" << endl;
cout << " " << endl;
cout << " " << endl;
system("pause");
return 0;
}
|
Any help will be appreciated. However, keep in mind that even if this code might not be perfect, etc, I am not planning on using something like arrays until I get it working or if it is a must.
Cheers,
Milan