traffic lights!!

This is a discussion on traffic lights!! within the C++ Programming forums, part of the General Programming Boards category; i need some help here... im tryin to make a program that simulates traffic lights at an intsection, using a ...

  1. #1
    Unregistered
    Guest

    Question traffic lights!!

    i need some help here...

    im tryin to make a program that simulates traffic lights at an intsection, using a some sort of time function from borland C++ like sleep() or somethin on those lines. basically what im tryin to do is have a text display sayin when the one side turns green, then yellow, then red, then left turn singal, then green again. (and i need this fer both sides of traffic) im am totally lost on how to do it. so what i want is a text program that tells when the light changes (on both sides). i would really really appreciate any assiastance as soon as possble thx.

  2. #2
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Ok here is the program.. I have done this only for yellow, green and red.. You can modify it to add other function. I have also attached the executable file of the program. in case your complier does not support the headers i have used... Try running the executable. It is zipped


    # include <iostream.h>
    # include <conio.h>
    # include <stdio.h>
    # include <iostream.h>
    # include <dos.h>
    main()
    {
    clrscr();
    int ti;
    char cg[14]=" TRAFIC TRAFIC";
    cout<<" How long do you want the delay to be between signals >> ";
    cin>>ti;
    clrscr();

    for(int i=0;i<14;i++)
    {
    gotoxy(5,5+i);
    cout<<cg[i];
    delay(100);


    }

    ti=ti*100;
    gotoxy(25,10);
    cout<<" First side";
    gotoxy(55,10);
    cout<<" Second side";
    int sig;
    sig=56;
    do

    {

    if(sig==26)
    sig=56;
    else
    sig=26;

    gotoxy(sig,12);
    cout<<"green ";
    gotoxy(sig,12);
    cout<<"red ";
    delay(ti);
    gotoxy(sig,12);
    cout<<"yellow ";
    delay(ti);
    gotoxy(sig,12);
    cout<<"green ";
    gotoxy(sig,12);
    cout<<"Green ";

    }

    while(ti>0);
    }
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vehiclular Traffic Monitoring
    By Renarudo in forum C++ Programming
    Replies: 1
    Last Post: 07-22-2008, 07:58 PM
  2. Rendering more than 3 dynamic lights crashes engine?
    By psychopath in forum Game Programming
    Replies: 3
    Last Post: 12-27-2005, 03:01 AM
  3. HTTP traffic meter
    By Carlos in forum Windows Programming
    Replies: 3
    Last Post: 10-02-2003, 05:27 PM
  4. traffic cones
    By iain in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 01-27-2002, 08:56 PM
  5. So you want website traffic?
    By Betazep in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-19-2002, 01:23 PM

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