Thread: Need Help

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    12

    Question Need Help

    I want to see an output as folloing .How can i make changes to see the output as following .
    Number=1
    Number=2
    Number=3
    Number=4
    Number=5
    Number=6
    Number=7
    Number=8
    Number=9
    Do you want to continue [Y----N]
    Number=11
    Number=12
    Number=13
    Number=14
    Number=15
    Number=16
    Number=17
    Number=18
    Number=19
    Do you want to continue [Y----N]

    My source code is as under..please make a changes to do above output.Thanks in advance...
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
        int num=1;
        clrscr();
        do
        {
           while(num!=10)
              {
                 printf("\n\tNumber=%d",num);
                 num+=1;
              }
                  num=1;
           printf("\n\tDo you want to continue [Y----N] ");
        }
           while(getche()=='y' ||getche()=='Y');
        }
    getch();
    
    Number=1
    Number=2
    Number=3
    Number=4
    Number=5
    Number=6
    Number=7
    Number=8
    Number=9
    Do you want to continue [Y----N]
    Number=1
    Number=2
    Number=3
    Number=4
    Number=5
    Number=6
    Number=7
    Number=8
    Number=9
    Code Tags by...guess who...

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) Use code tags. See that nice little thread that tells you to read it before posting code? How about you actually do that?

    2) Read the FAQ. 'void main' is wrong. The FAQ is a good thing to read.

    3) You want the modulus operator (%).

    Run the following code. Adjust as needed:
    Code:
    #include <stdio.h>
    int main( void )
    {
        int x;
        for( x = 0; x < 20; x++ )
            printf("%d mod 5 is %d\n", x, x%5 );
        return 0;
    }
    Look at what's going on, you'll then have your answer.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you

    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.


    Good Luck with your program,

    Kermi3
    Lead Moderator
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Popular pages Recent additions subscribe to a feed