1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
//figuresinput.cpp file
#include <iostream>
#include <cctype> // <--- Used to std::tolower() and std::toupper().
#include "figures.hpp"
using std::cout; using std::cin; using std::endl;
int main()
{
// <--- "h", "c", "i" and "j" are easy, but you should come up with a better name to describe
// what they are or do. It makes the code easier to follow.
int rows, h, c/*, i{ 5 }, j{ 10 }*/; // <--- "h" is unued. Defined "i" and "j" and gave them a
// value for testing. Later figured out they are not needed.
char input{}, f{ 'f' }; // <--- Changed these two to "char"s. Initialized variable "f" to "f"
// so there would be something to compare "input" to.
cout << "What shape do you want to make? " << endl;
cout << "1. Square " << endl;
cout << "2. Diagonal Line " << endl;
cout << "3. Bottom Triangle " << endl;
cout << "4. Top Triangle " << endl;
cin >> c;
cout << "Enter the size of the shape:" << endl;
cin >> rows;
if (c == 1) // <--- Changed. The "=" sets "c" equal to 1 Which evaluates to true. The "==" compairs "c" to 1.
{
cout << "Did you want the square to be filled or hollow? [f/h]: " << endl;
cin >> input;
if (std::tolower(input) == f) // <--- Changed. Added the "std::tolower(...)".
{ // <--- The {}s are not needed for one line unless you plan to add more later.
filledsquare(/*i, j,*/ rows); // <--- All you really need to send here is "rows".
} // <--- The {}s are not needed for one line unless you plan to add more later.
else
hollowsquare(/*i, j,*/ rows); // <--- Easier to read if on its own line.
}
if (c == 2) // <--- Changed.
{
diagonalline(/*i, j,*/ rows);
}
if (c == 3) // <--- Changed.
{
bottomtriangle(/*i, j,*/ rows);
}
if (c == 4) // <--- Changed.
{
toptriangle(/*i, j,*/ rows);
}
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue";
std::cin.get();
return 0;
}
|