Thread: Program is doing nothing...

  1. #1
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    139

    Program is doing nothing...

    Hello, I've been having some problems regarding program functionality. The other day I decided to write a small program which prints the 255 ASCII characters in an organized manner. The thing is, the program starts but does nothing at all, but sit there at Command Prompt. I finished reading SAMS Teach Yourself C++ in 21 Days and decided writing my own small programs, so I'm still somewhat a beginner in the sense that I have no real experience, so obviously, my strategies in this are a bit sloppy.

    Code:
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
       unsigned char x;
    
       for (unsigned short i = 0; i >= x; i++)
       {
          cout << x;
          if (x == 50 || x == 100 || x == 150 || x == 200)
             cout << endl;
       }
    
       cin.get();
       return 0;
    }

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Code:
       unsigned char x;
    
       for (unsigned short i = 0; i >= x; i++)
       {
          cout << x;
    There are three errors in these three (relevant) lines. Perhaps you should describe in plain English what these lines do.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    139
    Oh! I see the problem! Well, my compiler just now pointed out that I had x uninitialized. I didn't get any errors, but I did get that one warning. I'll check back when I fix it.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I recommend you turn your warnings up to max and always pay heed to them! Good code doesn't have any warnings! Good luck.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well, that fixes one error.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM