Couple problems with my "program"

Hi!

I started to learn C++ couple days ago via this sites tutorial, and I'm struggling a bit with pointers and classes. But anyway, I made a little "countdown program" and I was wondering if you could guide me a bit with this.

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
//// classes example
#include <iostream>           // Ignore #include's, I know I dont need more 
#include <stdio.h>            // than couple of those
#include <conio.h>
#include <time.h>
#include <string>
#include <dos.h>
#include <windows.h>
using namespace std;


int main (){

	
    int x=1;
	string a; 
	cout << "Choose (and type) 'seconds' or 'machine_time': ";
	cin >> a;
	cout << "You chose " << a << '\n';
	
	if (a=="seconds"){
		
		do{
			cout << "Enter countdown starting number (type zero ('0') to exit): ";
			cin >> x;
			if ( x==0)
			{
				cout << endl << "Thank you for using this program! \n";
				return 0;
			}
			
			else if (x>0)
				do{ 
					cout << x << ", "; x--; Sleep ( 1000 ); 
				}while ( x>=1 );
			
			else if (x<0)
				
				do{
					
					cout << x << ", "; x++; Sleep ( 1000 );
				}while (x <= (-1));
			cout << endl ;
		}while (x==0);
	}
	else {
		do{
			cout << "Enter countdown starting number (type zero ('0') to exit): ";
			cin >> x;
			if ( x==0)
			{
				cout << endl << "Thank you for using this program! \n";
				return 0;
			}
			else if (x>0)
				do{
					cout << x << ", "; x--;
				}
				while ( x>=1 );
			
			else if  (x<0)
				do{
					cout << x << ", "; x++; 
				}while (x <= (-1));
					cout << endl;
				}while (x==0);
			cout << endl;
		}while (x==0);
	
	return 0;
}
	

I got this code working after couple hours of adjusting. So basically what this program does is that you have to choose between seconds and "machine_time" and after that it´s just a simple countdown counter.

So first, I´d like that when countdown is on, I could press ESC and it would abort the countdown and return to "Enter countdown starting number (type zero ('0') to exit)" section.

Second thing I was thinking is that if I press ESC when I am on "Enter countdown starting..." section, it would return to first section where I have to choose between seconds and "machine_time".

Thanks in advance and sorry about lack of my english skills.

By the way, doesn't C++ work with Xbox, am I correct? If yes, can I run same code with PC and Xbox?

Bump.
closed account (N6A4jE8b)
I copied your code and all I can say is wow. I made a countdown myself once but that's pretty good what you did.

And I don't know much to help you with but your code is great nonetheless. :)
closed account (4Gb4jE8b)
well i understand you're only a few days into it, so i doubt you would know common formatting, but when you get a chance to take a look at a few source codes, see how they format it. It makes it easier to read when the formatting is standard.

What you're asking for are some loops on key enter. Now i personally don't know how to do it, but i think the key here would be the goto() and break() functions.

You're english is fine.

As for your question about the xbox, i'm going to say yes and no. Yes it is c++, no it's not a console application as you have been learning so far. It is formatted a different way, with different headers, and while certain things are likely the same as far as certain functions are concerned, many will be different. If you're looking for game programming, as opposed to software programming see this

http://www.cplusplus.com/forum/articles/28558/

and for a suggested game library (if you know how to get other programs as necessary as well) see here

http://www.thegamecreators.com/?m=view_product&id=2128
You can easily write games for XBOX and PC simultaneously with XNA Game Studio. Works inside Visual Studio, or any of the express editions. The applications, however, have to be written in C#.
Last edited on
western: Always glad to hear compliments, especially because I just started programming :)

headlessgargoyle:

Sure, I´ll take a look to some source codes when I got time/I'm bored.

In fact I lost the code that I used for that countdowner ( I was deleting stuff and accidentally erased save folder), so I don't need anymore help with that. At the moment I am making Tic-Tac-Toe game, and it looks promising :)

But damn I was planning to make console programs for Xbox! :P Just kidding.. Phh, well then I should start to look tutorials for Xbox coding, since I have been planning to start making XBLA game( probably some kind of platformer puzzle) as soon as I understand C++ "well".

Jaso333:

Okay, but I think I'll stick with C++, and go to C++0x(is it called C++1x nowadays?) as soon as it is published.


Just one more question, can I always use structs instead of classes? Aren't they same, except struct are public by default and classes are private?
Last edited on
Topic archived. No new replies allowed.