Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   lots of probelms w\functions (http://www.go4expert.com/forums/lots-probelms-wfunctions-t9255/)

jimJohnson 11Mar2008 22:44

lots of probelms w\functions
 
I am really having problems with this function project and any help would be great. If helping please try not to get too technical as I am new to functions and do not understand alot about them yet. I am gonna give all the information first and what I Have............


THESE ARE THE INSTRUCTIONS:

Write a program that asks the user to type in the height and width of a rectangle. It also asks the user to type in a character in which to fill the rectangle. The program prints the top and bottom of the rectangle using a hyphen ("-") and the sides using a pipe ("|"). The interior of the rectangle will be filled with the character the user types. Because of the fill character, the height and width of the rectangle cannot be less than 3, because if it is less than three, there would be no place to fill. If the user types an invalid height or width, the program should tell them it is invalid and ask them to type it in again. The program should keep accepting heights and widths until the user types a negative number for the height.

You should use the following functions:
Draw_Rectangle The height, width and character are passed into this function. It calls the functions Draw_Top_Bottom and Draw_Middle. Nothing is returned from this function.

Draw_Top_Bottom This function accepts an integer as the formal parameter and draws the top (or bottom) of the rectangle. Nothing is returned from this function.

Draw_Middle This function accepts the height, width and the filler character as the parameters and prints the rows of the rectangle. Nothing is returned from this function.

Get_Number This function has a prompt (a string) passed into the function and asks the user to type what the prompt asks. The function returns the number that is typed in. It does not check for the negative number (that is done in main)

Get_Character This function asks the user to type in the filler character and returns it.

THIS IS WHAT THE OUTPUT SHOULD LOOK LIKE

Programmed by <your name>

Type a negative for the height to exit!
Enter the height: 7
Enter the width: 5
Enter the character to fill the rectangle with: +
- - - - -
:+++:
:+++: (By the way i am trying to make this figure even out in spacing)
:+++:
:+++:
:+++:
_ _ _ _ _

Enter the height at the first prompt and the width at the second!
Type a -1 for the first prompt to exit!
Enter the height: 1
Invalid: Height cannot be less than 3.
Type a negative height to exit! Try again!!!
Enter the height: 0
Invalid: Height cannot be less than 3.
Type a negative height to exit! Try again!!!
Enter the height: 5
Enter the width: 1
Invalid: Width cannot be less than 3.
Try Again!!!
Enter the width: -4
Invalid: Width cannot be less than 3.
Try Again!!!
Enter the width: 2
Invalid: Width cannot be less than 3.
Try Again!!!
Enter the width: 10
Enter the character to fill the rectangle with: @

_ _ _ _ _ _ _ _ _ _
@@@@@@@:
@@@@@@@:
@@@@@@@:
_ _ _ _ _ _ _ _ _ _

Enter the height at the first prompt and the width at the second!
Type a -1 for the first prompt to exit!
Enter the height: 1
Invalid: Height cannot be less than 3.
Type a negative height to exit! Try again!!!
Enter the height: -4


THIS IS WHAT i HAVE:

Code:


#include <iostream>
using namespace std;
char Get_Character();
int Get_Number();
void Draw_Rectangle(int height, int width, char symbol);
void Draw_Top_Bottom(int width);
void Draw_Middle(int height, int width, char symbol);

int main()
{
        int height, width;
        char symbol;
       
        cout << "Programmed by Jim Johnson";
        cout << endl << endl;
        cout << "Type a negative for the height to exit!";
        cout << endl;
        cout << "Enter the height: ";
       
        height = Get_Number();

        if (height < 0)
                {
                        exit(1);
                }

        else
       
        cout << "Enter the width: ";
        width = Get_Number();

        cout << "Enter the character to fill the rectangle with: ";
        symbol = Get_Character();

        Draw_Rectangle(height, width, symbol);

        Draw_Top_Bottom(width);

        Draw_Middle(height, width, symbol);
       
        return 0;
}


int Get_Number()
{
        int x;
        bool inputInvalid = true;
        while (inputInvalid)
        {       
       
        cin >> x;
               
               
                if (x == 0  || x == 1 || x == 2)
                {
                        cout << "Invalid!! Height can not be less than 3." << endl << "Type a negative height to exit! Try Again !!!" << endl << "Enter the height: ";
                }
                else
                {
                inputInvalid = false;
        }
}
        return x;
}

void Draw_Rectangle(int width, int height, char symbol)
{
        Draw_Top_Bottom(width)

}

{
        Draw_Middle(symbol)
}

void Draw_Top_Bottom(int width)
{
       
        for (int count = 1; count <= width; count++)
        cout << '-';
}

void Draw_Middle(int height, int width, char symbol)

{


}



char Get_Character()
{


                for(int col = 0; col < width; ++ col)
                {
                       
                        cout << symbol;
                }
}



All times are GMT +5.5. The time now is 15:16.