using the info the user enters. but i cant figure out how to fix my code. The result I get when I run the program keeps giving the wrong amount of tiles.
#include <iostream>
usingnamespace std ;
/* Function Prototype */
void GetDim(int & tiles, int & courses);
/* From user, gets the desired number of tiles and courses. */
bool ValueCheck(int value);
/* Makes sure the user does not use zero or negative numbers. */
void Start(int courses);
/* Has a function with a loop to make the top of the tile. */
void MakeTiles(int tiles);
/* Has different fucntions within it.Each fuction has a loop
for the way the tile is portyrayed. */
void Row1(int tiles);
/* The loop used here gives the first line after the top of the tile. */
void Row2(int tiles);
/* The loop used here gives the second line after the top of the tile.*/
void Row3(int tiles);
/* The loop used here gives the third line after the top of the tile. */
void Row4(int tiles);
/* The loop used here gives the fourth line after the top of the tile. */
int main ()
{
int tiles, courses, value,t ;
GetDim(tiles, courses);
if (ValueCheck(tiles))
if (ValueCheck(courses))
{
t = courses;
Start(tiles);
while (t > 0)
{
t--;
MakeTiles(tiles);
}
}
cout << endl;
return 0;
}
/* function definition */
void GetDim(int & tiles, int & courses)
{
cout << "How many tiles wide do you want the floor to be? ";
cin >> tiles;
cout << "How many courses do you want in your floor? ";
cin >> courses;
}
bool ValueCheck(int value)
{
if (value < 1)
{
cout << "You have entered a bad value" << endl;
cout << endl;
returnfalse;
}
elseif (value >= 1)
returntrue;
}
/* function definition */
void Start(int tiles)
{
int t;
t = 1;
cout << " ";
while (t <= tiles)
{
if (t%2==1)
cout << "____";
else
cout << " ";
t++;
}
cout << endl;
}
/* function definition */
void MakeTiles(int tiles)
{
Row1(tiles);
Row2(tiles);
Row3(tiles);
Row4(tiles);
}
/* function definition */
void Row1(int tiles)
{
int t;
cout << " /";
for (int t = 1; t <= tiles; t++)
{
if (t%2==1)
cout <<" \\" ;
else
cout << " /" ;
}
cout << endl;
}
/* function definition */
void Row2(int tiles)
{
int t;
cout << "/";
for (int t = 1; t <= tiles; t++)
{
if (t%2==1)
cout <<" \\" ;
else
cout << "____/" ;
}
cout << endl;
}
/* function definition */
void Row3(int tiles)
{
int t;
cout << "\\ /";
for ( t <= 1; t < tiles; t++)
{
if (t%2==1)
cout <<" \\" ;
else
cout << " /" ;
}
cout << endl;
}
/* function definition */
void Row4(int tiles)
{
int t;
cout << " \\____/";
for (int t = 1; t < tiles; t++)
{
if (t%2==1)
cout <<" \\" ;
else
cout << "____/" ;
}
Hello there, I thought you're doing an interesting program so I edited you code. I am aware that it won't display the way you like it if the given width is even. I'll leave that for you to solve. Good luck, hope this helps..
#include <iostream>
usingnamespace std ;
/* Function Prototype */
void GetDim(int & tiles, int & courses);
/* From user, gets the desired number of tiles and courses. */
bool ValueCheck(int value);
/* Makes sure the user does not use zero or negative numbers. */
void Start(int courses);
/* Has a function with a loop to make the top of the tile. */
void MakeTiles(int tiles);
/* Has different fucntions within it.Each fuction has a loop
for the way the tile is portyrayed. */
void Row1(int tiles);
/* The loop used here gives the first line after the top of the tile. */
void Row2(int tiles);
/* The loop used here gives the second line after the top of the tile.*/
void Row3(int tiles);
/* The loop used here gives the third line after the top of the tile. */
void Row4(int tiles);
/* The loop used here gives the fourth line after the top of the tile. */
int main ()
{
int tiles, courses, value,t ;
GetDim(tiles, courses);
if (ValueCheck(tiles))
if (ValueCheck(courses))
{
t = courses;
Start(tiles);
while (t > 0)
{
t--;
MakeTiles(tiles);
}
}
cout << endl;
return 0;
}
/* function definition */
void GetDim(int & tiles, int & courses)
{
cout << "How many tiles wide do you want the floor to be? ";
cin >> tiles;
cout << "How many courses do you want in your floor? ";
cin >> courses;
}
bool ValueCheck(int value)
{
if (value < 1)
{
cout << "You have entered a bad value" << endl;
cout << endl;
returnfalse;
}
elseif (value >= 1)
returntrue;
}
/* function definition */
void Start(int tiles)
{
int t;
t = 1;
cout << " ";
while (t <= tiles)
{
if (t%2==1)
cout << "____";
else
cout << " ";
t++;
}
cout << endl;
}
/* function definition */
void MakeTiles(int tiles)
{
Row1(tiles);
Row2(tiles);
Row3(tiles);
Row4(tiles);
}
/* function definition */
void Row1(int tiles)
{
int t;
cout << " /";
//if (tiles%2==0) tiles--; // edited
for (int t = 1; t <= tiles; t++)
{
if (t%2==1)
cout <<" \\" ;
else
cout << " /" ;
}
cout << endl;
}
/* function definition */
void Row2(int tiles)
{
int t;
cout << "/";
for (int t = 1; t <= tiles; t++)
{
if (t%2==1)
cout <<" \\" ;
else {
cout << "____/" ; // edited
}
}
cout << endl;
}
/* function definition */
void Row3(int tiles)
{
int t;
cout << "\\";
for ( t = 1; t <=tiles; t++) // edited t = 1 not t <=1
{
if (t%2==1)
cout <<" /" ;
else
cout << " \\" ;
}
cout << endl;
}
/* function definition */
void Row4(int tiles)
{
int t;
cout << " \\"; // edited
for (int t = 1; t <= tiles; t++) // edited
{
if (t%2==1)
cout <<"____/" ; // edited
else
cout << " \\" ;// edited
}
cout << endl;
}