is this good for a 4th program I wrote in c++

Discussion in 'All other topics' started by stinkee2, Apr 10, 2009.

  1. stinkee2

    stinkee2 Member

    Joined:
    Oct 14, 2007
    Messages:
    78
    Likes Received:
    0
    Trophy Points:
    16
    this is a console application, I made a counter that goes up in increments of slightly under a second,the number it counts to is user defined. instead of explaing it im just gonna copy the output

    Code:
    enter a time to count to (NON ZERO!): 7
    
    Current Number: 1, counting is 14% done!
    
    Current Number: 2, counting is 28% done!
    
    Current Number: 3, counting is 42% done!
    
    Current Number: 4, counting is 57% done!
    
    Current Number: 5, counting is 71% done!
    
    Current Number: 6, counting is 85% done!
    
    Current Number: 7, counting is 100% done!
    
    COUNTING FINISHED
    the only reason I like this more than the other simple applications I made is because I only used the header stdio.h, I wanted to see if it was possible without windows.h or time.h
    here is how I did it...
    Code:
    #include <stdio.h>
    int wait()
    {
          int n = 0;
          while (1)
          {
                int counter = n / 10000;
                ++n;
                if(counter == 8000)
                break;
          }
    }
    int percent(int a, int b)
    {
         int p = (a * 100) / b; 
         return (p);
    }
    void clear()
    {
         for(int c; c < 20; c++)
         {
              printf("\n");
         }
    }
    int main()
    {
         int w;
         int i;
         printf("enter a time to count to (NON ZERO!): ");
         scanf("%d", &w);
         for(i = 1; i != (w + 1); i++)
         {
                 wait();
                 printf("\nCurrent Number: %d, counting is %d%% done!\n",i , percent(i, w));
         }
         printf("\nCOUNTING FINISHED");
         fflush(stdin);
         getchar();
    }
    
    the void clear() was to clear the screen without using system("cls");
    but it looked bad so I didnt use it, I forgot to take it out
    I wanted to make this as portable as possible so I could maby port it to my psp once I can make an on screen keyboard for it.
    ps.
    im only 14 years old and i did not take this code from anybody, I made it ( not too impressive though)
     
  2. aldan

    aldan Active member

    Joined:
    Mar 24, 2007
    Messages:
    1,725
    Likes Received:
    46
    Trophy Points:
    78
    its all greek to me but if it works,good on you mate.
     
  3. stinkee2

    stinkee2 Member

    Joined:
    Oct 14, 2007
    Messages:
    78
    Likes Received:
    0
    Trophy Points:
    16
    thanks, and yes it works exactly how I wanted it to
     
  4. homesick

    homesick Regular member

    Joined:
    Jun 12, 2013
    Messages:
    2,745
    Likes Received:
    1
    Trophy Points:
    46
    i dunno if its good for c++ or not as i don't know the code, but if you are just starting it looks like a solid program. keep working at it, and one day you will be making alot of money!
     

Share This Page