Struggling with if break

So, yesterday you kndly helped me breaking a loop but I realized I still don't understand how it works. I have as an example a very easy exercise. Using "for" I should print the table of the 10 first products of a number inserted by keyboard but this number must be between 1 and 10. This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{
    cout << "Basics For Exercise 3" << endl;

    int num;

    printf("Table of products of numbers between 1 and 10 \n");
    printf("Insert a number between 1 and 10: ");
    scanf("%d", &num);

        for (int i=1; i<=10; i++) {
            printf("%d x %d = %d \n",num,i,num*i);
    }
    return 0;
}


what I want to do is break the loop when user insert a number <1 and >10. How can I do that?

Thank you in advance.
using a bool to manage the while() loop:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

int main()
{
    bool fQuit {false};
    while (!fQuit)
    {
        std::cout << "Enter a number b/w 1 and 10: \n";
        int num{};
        std::cin >> num;
        if (num < 1 || num > 10)
        {
            fQuit = true;
        }
        else
        {
            for (size_t i = 1; i < 10; ++i)
            {
                std::cout << num * i << " ";
            }
            std::cout << "\n";
        }
    }
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>

int main()
{
    int number = 0 ;

    while( std::cout << "Enter a number between 1 and 10:  " &&
           std::cin >> number && number > 0 && number < 11 )
    {
        for( int multiplier = 1 ; multiplier < 11 ; ++multiplier )
        {
            std::cout << number << " x " << std::setw(2) << multiplier
                      << " == " << std::setw(3) << number*multiplier << '\n' ;
        }
    }
}


C
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>

int main()
{
    int number = 0 ;

    while( printf( "%s", "Enter a number between 1 and 10: " ) &&
           scanf( "%d", &number ) == 1 && number > 0 && number < 11 )
    {
        for( int multiplier = 1 ; multiplier < 11 ; ++multiplier )
            printf( "%d x %2d == %3d\n", number, multiplier, number*multiplier ) ;
    }
}
Thank you, solved!
Topic archived. No new replies allowed.