So I have to write a code that lets the user input an integer called size and i have to display a a square so that the length and width are determined by size. but i have to have what ever number size is, to the run diagonally through the square. for example if the user pick 4 it would display
###4
##4#
#4##
4###
all i can figure out is the first line and the last line. I am having trouble getting the number to move diagonally and I am having trouble getting the fill character to go after the number. my code looks like:
[code]
cout << "Please pick a size, from 1 through 9:" << endl;
cin >> size;
cout << setw(size) << setfill('#') << size << endl;
cout << left << setw(size) << setfill('#') << size << endl;
#include <iostream> // std::cout, std::endl
int main(){
int x = 4;
for (int r = 0; r < x; r++){
std::cout << std::endl;
for (int c = 0; c < x; c++)
if (r == c)
std::cout << x;
else
std::cout << '#';
}
std::cout << std::endl;
return 0;
}
Should be able to figure out how to do the diagonal the other way now.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int size = 0;
cout << "Please pick a size from 1 through 9: ";
cin >> size;
cout << endl;
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
if (x == y)
cout << size;
else
cout << '#';
}
cout << endl;
}
return 0;
}
If you enter 4 the output will be
4###
#4##
##4#
###4
It is a different angle then what you wanted but I'm not sure how to get it to go the other way.