Ask the user for a single digit number. Store as int.
Print a rectangle made of *'s with the number inside
Im only allowed to use cin, cout and variables
This is what I have so far how do I put the number in the middle
#include <iostream>
usingnamespace std; // <--- Best not to use.
int main()
{
int x{}; // <--- ALWAYS initialize all your variables.
cout << "Enter a single digit number: ";
cin >> x;
cout <<
"******************\n""* *\n""* *\n""* "
<< x <<
" *\n""* *\n""* *\n""* *\n""******************";
return 0; // <--- Not required, but makes a good break point for testing.
}
In your line 6 the "cin" needs the extraction operator, (>>) to work properly. Right now it just skips the the "cin" because there is nothing to extract into.
You do not need a "cout" for everyline. Good use of the (\n) though.
Lines 13 - 23 are set up to look more like your output, the compiler will ignore the extra white space. Lines 14 - 17 are considered just 1 string even-though they are on separate lines. And the same is true for lines 19 - 23.
I added 1 extra (*) on the first and last line and a space on the other lines to better center the number inside the box.