Whats wrong with my countdown program?

This is a discussion on Whats wrong with my countdown program? within the C++ Programming forums, part of the General Programming Boards category; #include <iostream> #include <conio.h> #include <conio.c> #include <string> #include <windows.h> using namespace std; void time(float counter, int x, int y, ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    156

    Whats wrong with my countdown program?

    #include <iostream>
    #include <conio.h>
    #include <conio.c>
    #include <string>
    #include <windows.h>

    using namespace std;

    void time(float counter, int x, int y, WORD color);

    int main()
    {
    time(2.00, 20, 0, FOREGROUND_BLUE);
    getch();
    return 0;
    }


    void time(float counter, int x, int y, WORD color)
    {
    HANDLE output=GetStdHandle(STD_OUTPUT_HANDLE);
    COORD cursor={x, y};

    SetConsoleCursorPosition(output, cursor);
    SetConsoleTextAttribute(output, color);

    for (int i=counter;i>=0.00;i-0.01) {
    cout << counter;
    Sleep(100);
    clrscr(); }
    }
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: goldenbunny84@hotmail.com

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  2. #2
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    in your for loop:

    Code:
    for (int i=counter;i>=0.00;i -= 0.01) 
    { 
        cout << counter; 
        Sleep(100);  
        clrscr(); 
    }
    try that
    the best things in life are simple.

  3. #3
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    or that loop could be your whole program...

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    nope, still bad. Its weird, it doesn't display the zeros after the decimal. By the way, I took xnlk's advice and also replaced in counter variable in the loop with an "i". It still doesn't do what I want it to do.(display the time on the top middle portion of the screen and countdown all the way to zero)
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: goldenbunny84@hotmail.com

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 02:42 AM
  2. Replies: 5
    Last Post: 01-13-2007, 02:14 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  4. Whats wrong with my program?
    By Ruflano in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2002, 05:09 PM
  5. what's wrong with my newbie program??
    By insoolated in forum C++ Programming
    Replies: 1
    Last Post: 09-14-2001, 09:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21