Computer Shop Application.

Hey Guys. I'm new to this so can you help me out with my code here?

#include <iostream.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>

void main(void)
{

int a = 0;
int h,m,s;
int h1=h, m1=m, s1=s;
int h2,m2,s2;
int fee = 0;
char code;

rep:
cout<<"\n\n\DragonForce Computer Shop";
cout<<"\n\nRATE: 1 PHP = 1 MINUTE";
cout<<"\n\nPCs Available";
cout<<"\n\n\nPC[1]\t\tPC[2]";
cout<<"\n\nPC[3]\t\tPC[4]";
cout<<"\n\nEnter PC you wish to activate: ";
cin>>code;
clrscr();

switch(code)
{
case '1': cout<<"\n\n\n\n\n\n\n--PC NUMBER 1 ACTIVATED--";
goto prog;

case '2': cout<<"\n\n\n\n\n\n\n--PC NUMBER 2 ACTIVATED--";
goto prog;

case '3': cout<<"\n\n\n\n\n\n\n--PC NUMBER 3 ACTIVATED--";
goto prog;

case '4': cout<<"\n\n\n\n\n\n\n--PC NUMBER 4 ACTIVATED--";
goto prog;

default : cout<<"\n\n\nINVALID PC. PLEASE TRY AGAIN ";
goto rep;
}



prog:
cout << "\n\n\nEnter the current hour --> ";
cin >> h;

cout << "\nEnter the current minute --> ";
cin >> m;

cout << "\nEnter the current second --> ";
cin >> s;

h2=h;
m2=m;
s2=s;

while (a == 0)
{


system("cls");

cout<<"\n\n\nTime started: ";
cout <<h<<":"<<m<<":"<<s;

cout<<"\n\n\nTime now: ";
cout<<h2<<":"<<m2<<":"<<s2;

cout<<"\n\n\nTime occupied: ";
cout<<h1<<":"<<m1<<":"<<s1<<" (TIME HERE IS 1 SECOND LATE)";

cout<<"\n\n\nFee to pay: ";
cout<<fee<<" PHP";

cout<<"\n\n\n\n\t\t[Fee starts at 1 PHP]";
cout<<"\n[If 1 hour is completed. Only 60PHP needs to be paid.]";


Sleep(1000);
s1++;
s2++;


if (s1 > 59)
{
s1 = 0;
m1++;
fee++;
}
if (s2 > 59)
{
s2 = 0;
m2++;
}

if (m1 > 59)
{
m1 = 0;
h1++;

}
if (m2 > 59)
{
m2 = 0;
h2++;
}
if (h2 > 24)
{
h2 = 0;
}
if (h1 > 24)
{
h1 = 0;
}


}
}

I'm having trouble running the timer/clock because when I put an if else before the end of the code like.

if (ans == 'y' || ans == 'Y')
goto rep;

the timer/clock won't function anymore. it only functions when i enter 'n' but then it will only run as many times as the 'n's I enter. and if I enter 'n' it would not let me enter anything else. It would only let me enter something else after it has run it's function. Would appreciate any help.
Last edited on
Try to make your code easier to read when you paste it. Use code tags [code][/code] around your code and use indents

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
#include <iostream.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>

void main(void)
{

	int a = 0;
	int h,m,s;
	int h1=h, m1=m, s1=s;
	int h2,m2,s2;
	int fee = 0;
	char code;

	rep:
	cout<<"\n\n\DragonForce Computer Shop";
	cout<<"\n\nRATE: 1 PHP = 1 MINUTE";
	cout<<"\n\nPCs Available";
	cout<<"\n\n\nPC[1]\t\tPC[2]";
	cout<<"\n\nPC[3]\t\tPC[4]";
	cout<<"\n\nEnter PC you wish to activate: ";
	cin>>code;
	clrscr();

	switch(code)
	{
	case '1': cout<<"\n\n\n\n\n\n\n--PC NUMBER 1 ACTIVATED--";
		goto prog;

	case '2': cout<<"\n\n\n\n\n\n\n--PC NUMBER 2 ACTIVATED--";
		goto prog;

	case '3': cout<<"\n\n\n\n\n\n\n--PC NUMBER 3 ACTIVATED--";
		goto prog;

	case '4': cout<<"\n\n\n\n\n\n\n--PC NUMBER 4 ACTIVATED--";
		goto prog;

	default : cout<<"\n\n\nINVALID PC. PLEASE TRY AGAIN ";
		goto rep;
	}



	prog:
	cout << "\n\n\nEnter the current hour --> ";
	cin >> h;

	cout << "\nEnter the current minute --> ";
	cin >> m;

	cout << "\nEnter the current second --> ";
	cin >> s;

	h2=h;
	m2=m;
	s2=s;

	while (a == 0)
	{


		system("cls");

		cout<<"\n\n\nTime started: ";
		cout <<h<<":"<<m<<":"<<s;

		cout<<"\n\n\nTime now: ";
		cout<<h2<<":"<<m2<<":"<<s2;

		cout<<"\n\n\nTime occupied: ";
		cout<<h1<<":"<<m1<<":"<<s1<<" (TIME HERE IS 1 SECOND LATE)";

		cout<<"\n\n\nFee to pay: ";
		cout<<fee<<" PHP";

		cout<<"\n\n\n\n\t\t[Fee starts at 1 PHP]";
		cout<<"\n[If 1 hour is completed. Only 60PHP needs to be paid.]";


		Sleep(1000);
		s1++;
		s2++;


		if (s1 > 59)
		{
			s1 = 0;
			m1++;
			fee++;
		}
		if (s2 > 59)
		{
			s2 = 0;
			m2++;
		}

		if (m1 > 59)
		{
			m1 = 0;
			h1++;

		}
		if (m2 > 59)
		{
			m2 = 0;
			h2++;
		}
		if (h2 > 24)
		{
			h2 = 0;
		}
		if (h1 > 24)
		{
			h1 = 0;
		}


	}
}


All of your goto's are completely pointless, you really shouldn't use goto's at all. I don't even really understand what your asking

I'm having trouble running the timer/clock because when I put an if else before the end of the code like.

if (ans == 'y' || ans == 'Y')
goto rep;


at no point is there an 'ans' in your code.
Okay. So I also don't get what your asking because as I have said. I ,still, am just a beginner. But instead. Let me just ask you. How would you do this for yourself. You need to make an application which will allow the user to monitor the time that his customers have used and how much they should pay. Basically, this is a PC Rental app. You should have a loop which will take you back to the main menu.
Hullo Viktor,

I would suggest using functions in this case. Their better than using goto statements, and it'll make your code a bit more organized.
Okay. How about this.

How can I make something appear when I press the escape button. Like when I press the escape button, that's the only time my "Do you want to go back to the main menu" would show up.

And another question.

How can I keep the timer/clock running while i'm on the main menu. So that, when I go to the main menu, the timer/clock would still be running and when I come back, it still is running.

Last question.

If the "other question" is solved. How can I stop the time and end the program.
Last edited on
For getting the current time (to the second) use time(NULL) found in <ctime>.
As for capturing each key press, don't go there. It's much easier to deal with you standard input stream cin (which normally comes from the keyboard) then to try to capture a key press event.
Okay. After every suggestion I've got and a little research. My program looks like this.

#include <iostream.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>

void type1(void);

class dforce
{
public:

void work(void)
{
int h,m,s;
int h1=h, m1=m, s1=s;
int h2,m2,s2;
int fee = 0;
int a = 0;
unsigned pw;
char ans;

pw=getch();
rep:
cout << "\n\n\nEnter the current hour --> ";
cin >> h;

cout << "\nEnter the current minute --> ";
cin >> m;

cout << "\nEnter the current second --> ";
cin >> s;

h2=h;
m2=m;
s2=s;

while(a == 0)
{
system("cls");

cout<<"\n\n[PRESS ESC TO GO BACK TO THE MAIN MENU]";

cout<<"\n\n\nTime started: ";
cout <<h<<":"<<m<<":"<<s;

cout<<"\n\n\nTime now: ";
cout<<h2<<":"<<m2<<":"<<s2;

cout<<"\n\n\nTime occupied: ";
cout<<h1<<":"<<m1<<":"<<s1;

cout<<"\n\n\nFee to pay: ";
cout<<fee<<" PHP";

pw = getch();
if (pw==27)
{
type1();
;break;
}

Sleep(1000);
s1++;
s2++;


if (s1 > 59)
{
s1 = 0;
m1++;
fee++;
}
if (s2 > 59)
{
s2 = 0;
m2++;
}

if (m1 > 59)
{
m1 = 0;
h1++;

}
if (m2 > 59)
{
m2 = 0;
h2++;
}
if (h2 > 24)
{
h2 = 0;
}
if (h1 > 24)
{
h1 = 0;
}
endl;
};
};
};


void main(void)
{
unsigned ans;

cout<<"\n\nPC RENTAL APPLICATION";
cout<<"\n\nCREATED BY: ME";
cout<<"\n\nPRESS ENTER TO CONTINUE";
cout<<"\n\nPRESS ESC TO EXIT";

ans = getch();

if (ans==13)
{
type1();
}

if (ans==27)
{

}
}



void type1(void)
{
dforce f;
char code;



rep:
clrscr();
cout<<"\n\n\DragonForce Computer Shop";
cout<<"\n\nRATE: 1 PHP = 1 MINUTE";
cout<<"\n\nPCs Available";
cout<<"\n\n\nPC[1]\t\tPC[2]";
cout<<"\n\nPC[3]\t\tPC[4]";
cout<<"\n\n[Enter PC # you wish to activate or Enter x if you want to exit]";
cout<<"\n\n\nEnter choice here --> ";
cin>>code;

if (code == 'x' || code == 'X')
{
goto exit;
}

clrscr();

switch(code)
{
case '1': cout<<"\n\n\n\n\n\n\n--PC NUMBER 1 ACTIVATED--";
cout<<"\n(Press any key to continue)";
f.work();break;

case '2': cout<<"\n\n\n\n\n\n\n--PC NUMBER 2 ACTIVATED--";
cout<<"\n(Press any key to continue)";
f.work();break;

case '3': cout<<"\n\n\n\n\n\n\n--PC NUMBER 3 ACTIVATED--";
cout<<"\n(Press any key to continue)";
f.work();break;

case '4': cout<<"\n\n\n\n\n\n\n--PC NUMBER 4 ACTIVATED--";
cout<<"\n(Press any key to continue)";
f.work();break;

default : cout<<"\n\n\nINVALID PC. PLEASE TRY AGAIN ";
goto rep;

exit:
}
}

I know it looks messy. Don't point out the obvious.

As for my problem.

How can I keep the timer/clock running while i'm on the main menu. So that, when I go to the main menu, the timer/clock would still be running and when I come back, it still is running on that PC. For example. I activated the timer/clock on PC1. How can I move to the main menu without ending the "timing" and lastly, how can I stop that "timing".
1
2
3
4
time_t startTime = time();
//do stuff that you want to time...
time_t stopTime = time();
time_t runningTime = stopTime - startTime;

You really need to go about this project a different way. What is your program supposed to do?
Topic archived. No new replies allowed.