General Questions

Feb 1, 2008 at 6:03pm
Hi everyone...

This is my first post. I've been trying to do a lot on my own, but am stuck and would like to get some help please.

Everything I have learned thus far I have learned by reading thru the tutorials and information in this site alone, in case that helps. I'm not looking to score points, but letting you all know where my info has come from. I am using the Dev-C++ compiler and so far happy with it.

Ok...my questions:

I am trying to do a program that takes an initial value (user input) for a time delay, and then another value (also user input) for the number to count down from.

The first value is a delay in milliseconds, is the time to delay between each count. What I'm trying to do is put in fractional values so that instead of having "1" millisecond delay, I can have 0.25 ms, or 0.1 ms...or whatever. Problem is, I can't seem to get the program to do this and then stop at the end so I can see what's happening. I HAVE tried initializing the necessary variables as "float" and what-not but none of that has worked. The program runs....but runs so fast and then the dialog box vanishes....can't see what it's doing.

I'm terrible at interpreting the nebulous error messages...and haven't found a resource (yet) for dealing with those...so that hangs me up a lot, but I read them when they show up to get use to it and do my best to figure out what they mean.

Also....I CAN make the program work for integer values of the delay, with "1" being the smallest. In this case I do NOT understand why I have to have TWO "getchar();" near the end of the program. But if both are not there, the program finishes and disappears...which is not what I want. I want it to sit there. I'm just doing this on my own....not being overly agressive with it, but am making decent progress I think.

Below is my code....if anyone can help...I'd appreciate it....thank you.
============================================================================
============================================================================
// Program counts down from user-input number with desired delay between each count.

#include <iostream>
#include <windows.h> //required to use the "sleep" function


using namespace std;

int main ()
{

int i;
int x;

cout << "How long to delay? (in milliseconds) ";
cin >> i;

cout << "Count down from what number? ";
cin >> x;

loop:
cout << x << ", ";

Sleep(i); //Sleep --> 1000 = 1 second

x--;

if (x > 1) goto loop;
cout << "FIRE!\n";

getchar();
getchar();
return 0;
}
=============================================================================
=============================================================================
Last edited on Feb 1, 2008 at 6:07pm
Topic archived. No new replies allowed.