It statement

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i, rows = 0, row_nr;
cin >> row_nr;
//if(row_nr > 1 && row_nr <= 30)
{
for (i = 1; i <= 3; i++)
{
for(int j=0;j<row_nr;j++)
{
cout << i + j*(row_nr)<< " ";
}
cout << endl;
}
}
return 0;
}



Have this code it gives me the result i want but i want the function to stop at the number 30 i think its the if statement i have comment it .
How many threads have you already created about this one program/problem?
That is doubleposting which wastes everyone's time.

On your first thread http://www.cplusplus.com/forum/general/234595/
I did ask you to use code tags.

Again, on your first post there was instruction:
User inputs an integer N from the range from 1 to 30. Write a program to display the numbers from 1 to N*N in a table with N*N size.

That does not mean "stop at 30". If the user gives '30', the last printed value must be 900.

Your approach:
1
2
3
4
5
6
int row_nr = 0;
std::cin >> row_nr;
if ( row_nr > 1 && row_nr <= 30 )
{
  // print table
}

is correct. It does print the table only if the user gives valid N.

There are two other approaches:

2. Keep asking input from user until a valid N is given. That requires a loop.

3. Clamp input into valid range. If the input is not in [1..30], then change the N into some valid value and print the table. For example:
1
2
if ( row_nr < 1 ) row_nr = 1;
if ( 30 < row_nr ) row_nr = 30;


Topic archived. No new replies allowed.