My best C++ Programs

This is a discussion on My best C++ Programs within the C++ Programming forums, part of the General Programming Boards category; You might want to correct a little bug. If you enter any other char but integers your program enters a ...

  1. #31
    Registered User
    Join Date
    Feb 2002
    Posts
    40

    little bug in your slot

    You might want to correct a little bug. If you enter any other char but integers your program enters a huge loop. You might want to enter something that will tell it to crash or return something saying its not numbers the person entered. If i knew how I would tell you hehe. But apart from that its a neat little thing you made there.
    cout << "Gotta love cpp\n";
    cout << "UIN: 825265\n";
    cout << "jake@dr.com\n;
    /* Hope I can know enough one
    day to make my very own notepad
    */

  2. #32
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    to fix the math replace the calculations for the allowance with this:
    Code:
    		day= (allowance/7.0);
    		second= (allowance/7.0/24.0/60.0/60.0);
    		minute= (day/24.0/60.0);
    		monthly = (allowance*4);
    		yearly = (allowance*52);
    		decade = (yearly*10);
    		hourly = (allowance/7.0/24.0);
    		century = (yearly*100);
    		mil = (century*10);
    also you should not call main from with in your program. Its better to put the whole main function in a while statement.
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  3. #33
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Lightbulb hmmm

    isometric:

    really? i shouldn't call the main function from within it? why? is it bad for the computer or something... or is it slower? hmm weird...

  4. #34
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Nothing like that only that its bad style and for some reason it constitutes a error on Borland 5.2 (standard) so it has to have some negative effect.
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  5. #35
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    another hmmm

    prelude:

    an easier way to make it spin is this:

    for (int p = 1; p<=1000; ++p)
    {
    slot1 = rand() % (HIGH - LOW + 1) + LOW;
    cout<<slot1<<" ";
    slot1 = rand() % (HIGH - LOW + 1) + LOW;
    cout<<slot1<<" ";
    slot1 = rand() % (HIGH - LOW + 1) + LOW;
    cout<<slot1<<" ";
    slot1 = rand() % (HIGH - LOW + 1) + LOW;
    cout<<slot1<<" ";
    slot1 = rand() % (HIGH - LOW + 1) + LOW;
    cout<<slot1;
    cout<<'\b'<<'\b'<<'\b'<<'\b'<<'\b'<<'\b'<<'\b'<<'\ b'<<'\b';
    }
    cout<<endl<<endl;

    and that should make them look like they are spinning 1000 times then stopping, i could put a delay in there liek Sleep(10) or something small, and then increase the sleep so it appears to be slowing...

    maybe you could change my code and put that in there somewhere hehe

  6. #36
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Cool ?

    MrJake:

    someone had a similar feedback saying that if you enter a char it will do an endless loop...

    yea im aware of it and no one in my part of the class could figure out how at the time, this was last semester and i didnt know that you could do cin.fail() and stuff like that...

    they were the only programs i had with me (on a floppy) and they were pretty good so i put em up

    but if you could fix the continuous loop be my guest i gave you the code

    thanks

  7. #37
    Registered User
    Join Date
    Jan 2002
    Posts
    11

    Wink

    I remember those innocent days of programming...

  8. #38
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Exclamation

    HOLY BAJEEBAZ!!!

    i was just looking at the download count of my zip files, and the 2 together have 84 downloads!!!!!!!

    i have a question:

    how would i make a header file out of this:

    void clrscr()
    {
    COORD coordScreen = { 0, 0 };
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD dwConSize;
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
    }
    it would be much easier than copying and pasting it every time i make a program that uses it no?

    and how do i change it from saying: "Quote" to "Code" or something to that effect? i saw someone do that...

  9. #39
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    ugh

    why didnt anyone else post their best programs...thats what this was for lol
    Paro

  10. #40
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    cuz my programs suck!

    all ghetto code~
    SS3X

  11. #41
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I've had this for a while, but it's still buggy. I remember that I thought it was neat at the time but I can't for the life of me remember what gave me the idea. Now that I think of it, I may rewrite it and solve the problems as well as update the processing for C++ declarations as well.

    Sorry, I don't have any of my best C++ programs that I can post without embarassing myself on this computer. Old stuff from programming classes
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    static int cDecl ( void );
    static void readTok ( void );
    static void firstIdent ( void );
    static void decl ( void );
    static void pointers ( void );
    static void arrays ( void );
    static void args ( void );
    
    struct Token { char tok; char buffer[200]; };
    struct Token stack[200];
    struct Token curr;
    int top = -1;
    
    int main( void )
    {
      printf ( "--Universal Declaration Translator--"
               "\n     written by Julienne Walker\n"
               "\nInstructions: Enter a C style\n"
               "declaration at the command line,\n"
               "excluding argument names for \n"
               "functions and ending with a semicolon.\n"
               "\nTo exit the program, type x and hit\n"
               "enter.\n"
               "\nExamples:\n"
               "const char* (*a)(int, char);\n"
               "int func(double *, double);\n"
               "char *a[50];\n"
               "int i;\n\n"
               "$: " );
      while ( 1 ) {
        firstIdent();
        decl();
        printf ( "\n" );
        printf ( "$: " );
      }
      return EXIT_SUCCESS;
    }
    
    int cDecl ( void )
    {
      char *word = curr.buffer;
      if ( !strcmp ( word, "const" ) ) {
        strcpy ( word, "constant" );
        return 1;
      }
      else if ( !strcmp ( word, "signed" ) ) return 2;
      else if ( !strcmp ( word, "unsigned" ) ) return 2;
      else if ( !strcmp ( word, "char" ) ) return 2;
      else if ( !strcmp ( word, "short" ) ) return 2;
      else if ( !strcmp ( word, "int" ) ) return 2;
      else if ( !strcmp ( word, "long" ) ) return 2;
      else if ( !strcmp ( word, "float" ) ) return 2;
      else if ( !strcmp ( word, "double" ) ) return 2;
      else if ( !strcmp ( word, "void" ) ) return 2;
      else if ( !strcmp ( word, "struct" ) ) return 2;
      else if ( !strcmp ( word, "enum" ) ) return 2;
      else return 3;
    }
    
    void readTok ( void )
    {
      char *temp = curr.buffer;
      while ( ( *temp = getchar() ) == ' ' ) ;
      if ( *temp == 'x' ) {
        printf ( "Good day\n");
        exit( 0 );
      }
      if ( isalnum ( *temp ) ) {
        while ( isalnum ( *++temp = getchar() ) ) ;
          ungetc ( *temp, stdin );
          *temp = '\0';
          curr.tok = cDecl();
          return;
      } else if ( *temp == '*' ) {
        strcpy ( curr.buffer, "pointer to" );
        curr.tok = '*';
        return;
      }
      curr.buffer[1] = '\0';
      curr.tok = *temp;
      return;
    }
    
    void firstIdent ( void )
    {
      readTok();
      while ( curr.tok != 3 ) {
        stack[++top] = curr;
          readTok();
      }
      printf ( "%s is a ", curr.buffer );
      readTok();
    }
    
    void decl ( void )
    {
      if ( curr.tok == '[' ) arrays();
      else if ( curr.tok == '(' ) args();
      pointers();
      while ( top >= 0 ) {
        if ( stack[top].tok == '(' ) {
          stack[top--]; readTok(); decl();
        } else printf ( "%s ", stack[top--].buffer );
      }
    }
    
    void pointers ( void )
    { while ( stack[top].tok == '*' ) printf ( "%s ", stack[top--].buffer ); }
    
    void arrays ( void )
    {
      while ( curr.tok == '[' ) {
        printf ( "array " );
        readTok();
        if ( isdigit ( curr.buffer[0] ) ) {
          printf ( "0 - %d ", atoi ( curr.buffer ) - 1 );
          readTok();
        }
        readTok();
        printf ( "of " );
      }
    }
    
    void args ( void )
    {
      printf ( "function that takes a " );
      while ( curr.tok != ')' ) {
        readTok();
        printf ( "%s ", curr.buffer );
        readTok();
        if ( curr.tok == '*' ) printf ( "pointer " );
        if ( curr.tok != ')' ) {
          readTok();
          if ( curr.tok == ',' ) printf ( "and " );
        }
      }
      readTok();
      printf ( "as arguments and returns " );
    }
    -Prelude
    My best code is written with the delete key.

  12. #42
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Question

    What does that do? could you compile it and attach a zip file with the exe in it LOL, i wanna see what that does, i cant understand half the code...man i cant wait to learn all that
    Paro

  13. #43
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Cool

    lol my first thread has 420 views already
    Paro

  14. #44
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    here's my program....

    this is my first semester final project too......


    i also has the annoying enter a letter and the program will die glitch too, sorry maybe someday ill fix it
    Attached Files Attached Files

  15. #45
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >What does that do?
    It's a declaration translator. If you enter a C style declaration on the command line then the program will give you the english equivalent. Here's some sample output, but the full code is there and you can compile and run it to try it out.
    Code:
    --Universal Declaration Translator--
         written by Julienne Walker
    
    Instructions: Enter a C style
    declaration at the command line,
    excluding argument names for 
    functions and ending with a semicolon.
    
    To exit the program, type x and hit
    enter.
    
    Examples:
    const char* (*a)(int, char);
    int func(double *, double);
    char *a[50];
    int i;
    
    $: double *arg(float, int, double);
    arg is a function that takes a float and int and double as arguments and returns pointer to double
    
    $: const char *(*arg)(char, char, double);
    arg is a pointer to function that takes a char and char and double as arguments and returns pointer to char constant
    
    $: char string[50];
    string is a array 0 - 49 of char
    
    $: int i;
    i is a int
    
    $: x
    Good day
    Press any key to continue
    There is a small error that I fixed from the code I posted though, simply change the args function to this
    Code:
    void args ( void )
    {
      printf ( "function that takes a " );
      while ( curr.tok != ')' ) {
        readTok();
        printf ( "%s ", curr.buffer );
        readTok();
        if ( curr.tok == '*' ) printf ( "pointer " );
        if ( curr.tok != ')' ) {
          if ( curr.tok == ',' ) printf ( "and " );
        }
      }
      readTok();
      printf ( "as arguments and returns " );
    }
    -Prelude
    My best code is written with the delete key.

Page 3 of 8 FirstFirst 12345678 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 07:32 AM
  2. How come Dev C++ cant run some programs??
    By Sephiroth in forum C Programming
    Replies: 41
    Last Post: 09-17-2005, 06:35 AM
  3. Way to get the current open programs displayed?
    By CPPguy1111 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2005, 01:24 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 04:12 AM

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