lost push the button console app

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

34 Replies - 5915 Views - Last Post: 24 July 2010 - 03:20 PM Rate Topic: -----

#1 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

lost push the button console app

Posted 18 July 2010 - 02:08 PM

I am making a console app where you have to enter the numbers every 108 minutes like in the show "lost"
This is what i want to do have a countdown from 108 minutes (i pretty sure i have this part under control) and have it where you can only enter the numbers 4 8 15 16 23 42 when the countdown reaches 4 minutes left (I don't know how to do this part) and then i want to have it keep a log of how many times the timer has gone down to zero and how many days you've had it going continuously whit out it reaching zero i don't want you to do it for me because that takes all the fun out of it but give me good methods of doing this. I didn't really want to post the code yet because it kinda sloppy because i haven't organized it and i am always afraid someone is just going to copy it and say they did it.

Is This A Good Question/Topic? 0
  • +

Replies To: lost push the button console app

#2 taylorc8  Icon User is offline

  • B&

Reputation: 149
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Re: lost push the button console app

Posted 18 July 2010 - 06:56 PM

here's what I would start with

#include <iostream>
#include <fstream>
#include <string>
#include <sstream> //possibly used.
#include <iomanip> //possibly used.
#include <ctime>


I wouldn't copy your code, it's not mine, and it's probably buggy. ;)
Was This Post Helpful? 0
  • +
  • -

#3 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: lost push the button console app

Posted 19 July 2010 - 04:21 PM

Also how can i do this. I want a timer to run in the background of the program so like for example say you've been pushing the button every 108 minutes for 7 days with out the count down going to zero i want it to know that but not sure what would be a good method.
Was This Post Helpful? 0
  • +
  • -

#4 taylorc8  Icon User is offline

  • B&

Reputation: 149
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Re: lost push the button console app

Posted 19 July 2010 - 04:48 PM

Welcome to programming. The hard part isn't writing the code, it's designing it.
Was This Post Helpful? 2
  • +
  • -

#5 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: lost push the button console app

Posted 19 July 2010 - 04:50 PM

View Posttaylorc8, on 19 July 2010 - 03:48 PM, said:

Welcome to programming. The hard part isn't writing the code, it's designing it.

? I don't understand? One thing i've been writing in C++ for awhile i didn't just start
Was This Post Helpful? 0
  • +
  • -

#6 taylorc8  Icon User is offline

  • B&

Reputation: 149
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Re: lost push the button console app

Posted 19 July 2010 - 05:21 PM

When the countdown reaches four minutes left and under, you will want to allow the user to enter the code, right?

Multi-threading may be a possible solution to some of your problems. If you're asking me to make complete pseudo-code or listings of classes/functions used... That just takes the whole point out of your project, doesn't it?


There are numerous books on software design/engineering, most of which *should* teach you the basics of creating the kind of design and program structure your program will use, and hopefully it should be well-documented, and easy to modify later.

All the software engineering approaches to designing a program aside, I would personally begin working on a timer class to suit the needs of the program, as it does seem to be a large part of it.

Some approaches to software design include top-down, bottom-up, functional decomposition, Round-trip gestalt design, OOD (object oriented design, in which programs simulate physical objects and processes in the real world) and others, as I said, there are books on this, and probably some good ones.
Was This Post Helpful? 0
  • +
  • -

#7 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: lost push the button console app

Posted 19 July 2010 - 05:26 PM

View Posttaylorc8, on 19 July 2010 - 04:21 PM, said:

When the countdown reaches four minutes left and under, you will want to allow the user to enter the code, right?

Multi-threading may be a possible solution to some of your problems. If you're asking me to make complete pseudo-code or listings of classes/functions used... That just takes the whole point out of your project, doesn't it?


There are numerous books on software design/engineering, most of which *should* teach you the basics of creating the kind of design and program structure your program will use, and hopefully it should be well-documented, and easy to modify later.

All the software engineering approaches to designing a program aside, I would personally begin working on a timer class to suit the needs of the program, as it does seem to be a large part of it.

Some approaches to software design include top-down, bottom-up, functional decomposition, Round-trip gestalt design, OOD (object oriented design, in which programs simulate physical objects and processes in the real world) and others, as I said, there are books on this, and probably some good ones.

I'm quoting what i said in my very first post "i don't want you to do it for me because that takes all the fun out of it but give me good methods of doing this." I never wanted someone to write the code out for me i hate it when i see on programming forums someone ask for just that and I'm like why are you programming if you ask someone else to do it for you programming is the fun part.
Was This Post Helpful? 0
  • +
  • -

#8 godmoktail  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 76
  • Joined: 10-May 08

Re: lost push the button console app

Posted 19 July 2010 - 05:37 PM

It sounds like he wants us to go through a software development process with him. I'll give you an order to complete this task, which can be used for most if not all small scale projects like these.

Requirements - write what you want the program to accomplish. Sort of the stuff from your first post. Things such as File I/O, timing, reports, etc.

Analysis - Using what your requirements are, analyze how you can modularize your program (classes or functions). Threads, maybe a single function with a timer and conditional statements, etc. Try to figure out essential data, outline the flow of data, and how structures relate to each other and interact. Also, UML diagrams help, or flow charts, etc. A teacher in high school once told me, "When in doubt, draw it out."

Design - At this stage you can refine your previous analysis. Here you can try doing some pseudocode too, if you want.

Implement - Use pseudocode and design & analysis to start coding.

Throughout the process, document (comments, data dictionaries if you want to) and test.

Sorry if it sounds huge, but, I think this form of thinking eliminates much problems later on.

Incremental development if you are having trouble seeing the big picture. (Timer, then asking for a key press at a certain time, then resetting the counter and keeping track of button presses, etc, etc)

This post has been edited by godmoktail: 19 July 2010 - 05:40 PM

Was This Post Helpful? 1
  • +
  • -

#9 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: lost push the button console app

Posted 19 July 2010 - 06:07 PM

Ha Ha no i don't want you to go through a software development process with me. Maybe you guys misunderstood me I'm not just starting it it has 161 lines of code and is pretty much finished there were just a few things i didn't know how to do. Plus I'm not a noobie ether i've been programming in C++ for a while. Rereading this post it sounds a bit rude (maybe it's just me that thinks that) but i didn't intend for it to sound that way
Was This Post Helpful? 0
  • +
  • -

#10 taylorc8  Icon User is offline

  • B&

Reputation: 149
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Re: lost push the button console app

Posted 19 July 2010 - 06:16 PM

Maybe you should post your code, who really cares about a "lost push the button console app" anyway? There are many DIC members willing to offer suggestions.

This post has been edited by taylorc8: 19 July 2010 - 06:17 PM

Was This Post Helpful? 0
  • +
  • -

#11 c0dy  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 34
  • Joined: 29-June 10

Re: lost push the button console app

Posted 19 July 2010 - 06:28 PM

What about the part where 'Walt types' to Michael?

Well, if you want to keep track of how long the program runs...
you can record date and time the app started, store it... and
when the program is closed, it can store that time and do some
simple subtraction time2 - time1.

It doesn't really sound that difficult to be honest. It's for
the most part simple input validation. The only part I would
have to look up is how to make it so nothing appears when a
person tries to input from keyboard before 4 minutes is reached.
Sort of like a simulated frozen terminal with a flashing cursor.
Was This Post Helpful? 0
  • +
  • -

#12 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: lost push the button console app

Posted 19 July 2010 - 06:31 PM

View Posttaylorc8, on 19 July 2010 - 05:16 PM, said:

Maybe you should post your code, who really cares about a "lost push the button console app" anyway? There are many DIC members willing to offer suggestions.

Ha Ha yeah i guess your right what i was worried about was a noobie copying it. I'll post it in a bit i wanted to do some more construction on it. Thanks for your time.
Was This Post Helpful? 0
  • +
  • -

#13 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: lost push the button console app

Posted 19 July 2010 - 06:50 PM

View Postc0dy, on 19 July 2010 - 05:28 PM, said:

What about the part where 'Walt types' to Michael?

Well, if you want to keep track of how long the program runs...
you can record date and time the app started, store it... and
when the program is closed, it can store that time and do some
simple subtraction time2 - time1.

It doesn't really sound that difficult to be honest. It's for
the most part simple input validation. The only part I would
have to look up is how to make it so nothing appears when a
person tries to input from keyboard before 4 minutes is reached.
Sort of like a simulated frozen terminal with a flashing cursor.

Ha Ha a fellow lost fan are you?
Was This Post Helpful? 0
  • +
  • -

#14 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: lost push the button console app

Posted 19 July 2010 - 06:57 PM

Well this program idea actually presents you will a little problem. C/C++ input is normally "blocking" which means that when you ask stdin for input the program halts until the user presses enter (unless there is already data in the buffer).

The problem is that if the user does not enter any data then you program will just sit there... not good.

So you have two choices:

Multi-threaded -- neat, but more trouble than its worth here.
Non-blocking-io and polling -- this is pretty easy, you make a loop and you check the status of the input buffer, then you check the status of the clock, update the display, then loop back arround, over and over and over. -- This is the kind of loop that games tend to use, and this is probably what you want for your little game too.

assuming your OS is windows:

Now older DOS days we could just use kbhit() function, unfortunately this is depreciated (you can use _kbhit()) but its semantics are slightly different from the old DOS days... _kbhit() returns true if there is a char in the input buffer which you can read with _getch() -- however I will probably get tared and feathered for even suggesting you use conio.h functions!)
Was This Post Helpful? 1
  • +
  • -

#15 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: lost push the button console app

Posted 19 July 2010 - 07:23 PM

here is a neat little example program, this one uses GetAsyncKeyState to monitor the state of the space bar. The neat thing about this program is that it will register the pressing of the space bar even if the program in not in the forground. Enjoy :)

#include <windows.h>
#include <iostream>
#include <ctime>
using namespace std;

const unsigned long interval1 = 10000;
const unsigned long interval2 = 1000;

const char message[] = "\n\nPress SPACEBAR Please";

int main() {
    clock_t messageTime = clock();
    clock_t dotTime = clock();
    cout << message << flush;
    while(1) {
        if (clock() - messageTime > interval1) {
            cout << message << flush;
            messageTime = clock();
            dotTime = clock();
        } else if (clock() - dotTime > interval2) {
            cout << '.' << flush;
            dotTime = clock();
        }
        if (GetAsyncKeyState(VK_SPACE)) { break; }
    }
    return 0;
}

Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3