0

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;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Josh3.14
  • 15
  • 2
  • Lookup _reference parameters_ regarding that. – πάντα ῥεῖ Oct 27 '20 at 18:03
  • you can define a method in c++ that can actually modify the values you give as parameter even after the return... as @πάνταῥεῖ said, lookup for reference parameters – ΦXocę 웃 Пepeúpa ツ Oct 27 '20 at 18:07
  • 3
    There are two ways to return multiple variables from a function: 1) passing individual parameters by reference/pointer, or 2) `return`'ing a `struct`/`class`/`std::tuple` (or passing one as a reference/pointer parameter) – Remy Lebeau Oct 27 '20 at 18:07

0 Answers0