Adding a user input

My question is:

I have made this simple code that prints a 7 x 7 grid with the middle row and column printing a "." instead of "*". How would I adjust this code to require the user to choose the number of rows and columns, assuming that they will pick an odd number and the middle row/column will still print a "."
This is what the output currently looks like:

* * * . * * *
* * * . * * *
* * * . * * *
. . . . . . .
* * * . * * *
* * * . * * *
* * * . * * *

#include "stdafx.h"
#include <iostream>


int main()
{
for (int row = 0; row < 7; row++) // Define amount of rows
{
for (int col = 0; col < 7; col++) // Define number of columns within each row
{
if (row == 3 || col == 3)
{
std::cout << ". "; // Print if the value equals 3
}
else
{
std::cout << "* "; // Print if value equals anything else
}
}
std::cout << std::endl;
}
return 0;
}
You need a variable for cols - I assume that number of cols and rows are the same.
Get the user to input the number of cols - making sure that they are odd.
Set the middle to cols / 2. USe these two vars in your for loop.
Topic archived. No new replies allowed.