While inside a do-while

0

My problem is that when trying to repeat a program with a while inside, the program did not show me anything.

This is my code:

main()
{
     int i=1;

   do
   {

     printf("\nPrograma 'Serie 1-10'");

     getch();

    while(i<=10)
    {
        printf("%i, ", i);
        i++;
    }

    getch();

    printf("\nDesea repetir el programa 'Serie 1-10'? S/N ");
            scanf("%s", &continuar);
            system("cls");

  }while(continuar == 's'|| continuar =='S');
}
    
asked by Esteban Andres 03.10.2017 в 00:18
source

2 answers

0

Good afternoon, the getch () ; it stops the program until a key is pressed, in addition to the fact that the continue variable is never declared. Another point is that it will only print once the series (1 to 10) since the value of i on the second occasion you want to show the numbers will be worth 11. I leave the code with the modification .

    void main()
    {
       char continuar;
       do
       {
            int i=1;
            printf("\nPrograma 'Serie 1-10'");     

            while(i<=10)
            {
                printf("%i, ", i);
                i++;
            }

            printf("\nDesea repetir el programa 'Serie 1-10'? S/N ");
            scanf("%s", &continuar);
            system("cls");

      }while(continuar == 's'|| continuar =='S');
    } 
    
answered by 03.10.2017 в 01:25
0

The continue variable is not declared, and when it repeats the do loop, the i of the internal loop is at its maximum value, that is, 11 it is necessary to reset in each iteration, and to read the variable use cin, Greetings

int i = 1;
char continuar;

do
{
    printf("\nPrograma 'Serie 1-10'\n");

    //getch();
    system("pause");

    while(i<=10)
    {
        printf("%i, ", i);
        i++;
    }

    i = 1;

    printf("\n\nDesea repetir el programa 'Serie 1-10'?\n S/N: ");
    cin >> continuar;
    system("cls");

}while(continuar == 's' || continuar == 'S');
    
answered by 03.10.2017 в 01:32