I am trying to write a program that uses a user defined function. It will prompt the user to enter a valid height and valid width. After these two numbers are validated, it will then print a row of x's ( with height being how many rows pring, and with being the number of x's within each row.)
#include <iostream>
usingnamespace std;
void box(int);
int main()
{
int h, w;
box(2);
cout << "Enter height (0-25): " << endl;
cin >> h;
cout << "Enter width (0-25): " << endl;
cin >> w;
if (h < 0 || h > 25 || w < 0 || w > 25){
cout << "invalid number";
cout << "Please enter a number between 0 and 25: " << endl;
}
elseif (h > 0 && h < 25 && w > 0 && w < 25){
for (int x = 1; x <= h; x += h) {
cout << "X" << x << endl;
}
for (int y = 1; y <= w; y += w) {
cout << "X" << y << endl;
}
}
elseif(){
cout << "Please enter a number between 0 and 25: " << endl;
}
cout << "Exiting..." << endl;
return 0;
}
Error messages include:
Error 2 error C2059: syntax error : ')' c:\users\nicole\documents\visual studio 2013\projects\consoleapplication3\consoleapplication3\source.cpp 30 1 ConsoleApplication3
Error 3 error C2143: syntax error : missing ';' before '{' c:\users\nicole\documents\visual studio 2013\projects\consoleapplication3\consoleapplication3\source.cpp 30 1 ConsoleApplication3
Error 4 error C1075: end of file found before the left brace '{' at 'c:\users\nicole\documents\visual studio 2013\projects\consoleapplication3\consoleapplication3\source.cpp(8)' was matched c:\users\nicole\documents\visual studio 2013\projects\consoleapplication3\consoleapplication3\source.cpp 38 1 ConsoleApplication3
5 IntelliSense: expected an expression c:\Users\Nicole\Documents\Visual Studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Source.cpp 34 11 ConsoleApplication3
for (int x = 1; x <= h; x ++)
{
{
for (int y = 1; y <= w; y ++)
cout << "X" ;
}
cout << endl;
}
delete the reference to box[2]
Try starting with getting it running properly without the error checking else's and if's and maybe use a while statement once you solve the X's displaying properly.