Hey. So I'm supposed to build a program that will allow me to create a hollow square up to 20 characters long and wide depending on how many you enter. My instructor also wanted us to create a sentinel that would end the program if you entered a number below 1 or above 20. Here is the code.
// Lab 2a, Typewriter Graphics
// Programmer: Jesse Burns
// Editor(s) used: JNotePad
// Compiler(s) used: VC++ 2010 Express
// The necessary C++ file library
// Jesse Burns, Lab 2a.
cout << "Lab 2a, Typewriter Graphics\n";
cout << "Programmer: Jesse Burns\n";
cout << "Editor(s) used: JNotePad\n";
cout << "Compiler(s) used: VC++ 2010 Express\n";
cout << "File: " << __FILE__ << endl;
cout << "Compiled: " << __DATE__ << " at " << __TIME__ << endl << endl;
//Necessary input and counter for program to run
int i = 1;
int j = 1;
//Enter the size of the square you would like
cout << "Enter a side of square between 1-20: "<<endl;
cin >> buf; num = atof(buf.c_str());
//This code block creates the loop/counter loop that
//will run for that size until you enter a sentinel
//number that will end the program if you enter that
//number that is not between 1-20
if (num < 1 || num > 20)break;
if ( i <= num && j <= num )
if ( i == 1 || i == num || j == 1 || j == num )
cout << "*"<<endl; // if any one out of 4 argument is true then it will print * otherwise ' '
cout << " "<<endl; // prints if i=2 and j = 2
It builds the first and last character, but doesn't loop it all the way around. Plus, it's not returning so you can exit the program via enter key. Which is strange, because it first started doing that when I entered the while(true) loop with the if()break.