I attempting to make a program that allows the user to customize the U.S flag, though I've hit a snag. I want to return the flagHeight
, flagWidth
, and starArea
variables back to the main()
function, so they can be used in the output for
statement.
My goal is to have two functions; the main()
function where that output will be displayed, and a second function that takes the user input.
Any thoughts on how I could accomplish this?
#include <iostream>
using namespace std;
double input_Flag();
double input_Flag()
{
double flagWidth;
double flagHeight;
double starArea;
int restriction_1 = 5;
int restriciton_2 = 70;
do
{
cout << "Enter the flag width you would like (between 5 <--> 70): ";
cin >> flagWidth;
cout << endl;
if (flagWidth >= restriction_1 and flagWidth <= restriciton_2)
{
cout << "Your width is |" << flagWidth << "|";
cout << endl;
continue;
}
} while (flagWidth < restriction_1 or flagWidth > restriciton_2);
do
{
cout << "Enter the flag height (between 5 <--> " << flagWidth << "): ";
cin >> flagHeight;
cout << endl;
if (flagHeight >= restriction_1 and flagHeight <= flagWidth)
{
cout << "Your height is |" << flagHeight << "|";
cout << endl;
continue;
}
} while (restriction_1 > flagHeight or flagWidth < flagHeight);
do
{
cout<<"Enter the star area (area < " << flagHeight << "):";
cin>>starArea;
cout << endl;
if (starArea < flagHeight)
{
cout << "Your star area of the flag is |" << starArea << "|";
cout << endl;
continue;
}
} while (1 > starArea or starArea >= flagHeight);
}
void myPause()
{
cout << "[Press ENTER to see your flag]";
cin.clear();
cin.sync();
cin.get();
}
int main()
{
cout << "Welcome! Customize Your Flag below!" << endl;
cout << endl;
input_Flag();
cout << endl;
myPause();
cout << endl;
for(int x = 1; x <= flagHeight; x++)
{
for(int y = 1; y <= flagWidth; y++)
{
if(x <= starArea and y <= starArea)
cout << "*";
else
cout << "=";
}
cout << endl;
}
cout << "Awesome flag!" << endl;
return 0;
}