Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,916 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,736 people online right now. Registration is fast and FREE... Join Now!




Program error

 
Reply to this topicStart new topic

Program error, Getting a repeat of my answer

Entropicvamp
31 Mar, 2008 - 03:12 PM
Post #1

New D.I.C Head
*

Joined: 31 Mar, 2008
Posts: 14


My Contributions
My code works fine, but I cannot seem to figure out where I am getting the repeat of triangles. I have to only have one set show, but for some reason I get a repeat of triangles going down at least 5 to 6 times in a column, could someone help me out with where I am wrong in this code. It does work but I get it repeating it when it should be only once.
CODE
# include <iostream>

using namespace std;

void drawBar(int userInput);
void printTriangle(int userInput);


int main ()

{
    int userInput = 0;
    
    cout << "Enter the triangle base size: ";
    cin >> userInput;

    drawBar(userInput);
    printTriangle(userInput);

return 0;
}

//Function Definitiion
void drawBar(int userInput)
{
    for (int a = 1; a <= userInput; a++)
    {
        printTriangle(userInput);
    }
    cout << endl;
}

void printTriangle(int userInput)
{
    for (int a = 1; a <= userInput; a++)
    {
        for (int b = 1; b <= a; b++)
            {
                if (b <= userInput)
                    cout << "*";
                else
                    cout << "";
                }
             cout << endl;
            }
   }

User is offlineProfile CardPM
+Quote Post

pertheusual
RE: Program Error
31 Mar, 2008 - 03:26 PM
Post #2

D.I.C Head
**

Joined: 26 Jan, 2008
Posts: 231



Thanked: 3 times
My Contributions
cpp

drawBar(userInput);

in main shouldn't be there, right? It calls printTriangle several times, but you are already calling printTriangle.

Per
User is offlineProfile CardPM
+Quote Post

Entropicvamp
RE: Program Error
31 Mar, 2008 - 03:46 PM
Post #3

New D.I.C Head
*

Joined: 31 Mar, 2008
Posts: 14


My Contributions
QUOTE(pertheusual @ 31 Mar, 2008 - 04:26 PM) *

cpp

drawBar(userInput);

in main shouldn't be there, right? It calls printTriangle several times, but you are already calling printTriangle.

Per

Thank you, and thanks for pointing that out. I was going over it and I didn't even notice that. Amazing how even the simplest of things can make a major difference. Much appreciated.
User is offlineProfile CardPM
+Quote Post

pertheusual
RE: Program Error
31 Mar, 2008 - 03:51 PM
Post #4

D.I.C Head
**

Joined: 26 Jan, 2008
Posts: 231



Thanked: 3 times
My Contributions
No problem.
It's always the little things. smile.gif

Per
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:07PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month