Thread: Help with beginning program

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    3

    Help with beginning program

    In my book is says to write a program in its little review section. (I only want to make the first pattern, so that's all I'm gonna type out. ) I can't figure out how to print a character in increasing number for the life of me. I can do it easily with integers, but I have no idea how to do it with non integers. It's driving me nuts.

    Here are it's instructions

    Write a program that prints the following patters separately on below the other. Use "for" loops to generate the pattersn. All asterisks(*) should be printed by a single statemnt of the form "cout << '*';" (this causes the asterisks to print side by side) Hint: The last two patterns require theat each line begin with an appropriate number of blanks.

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    this question has been covered [understatement]many[/understatement] times. Do a search on this board and you will come up with tons of helpful answers.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    35
    Here's a hint : You can print as many asterisks as you want, they all end up on the same line* - that is, untill you print a newline character.


    *Technically anyway, the console does wrapping automagically.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    3
    nevermind guys. I was able to figure it out.

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    7
    wow..i actually did it.I hope no one minds me posting my code here

    Code:
    #include <iostream>
    void star(int x);
    int main()
    {
    int x;
    for (x=0;x<10;x++)
    {
    star(x);
    std::cout<<"\n";
    }
    return 0;
    }
    void star(int x)
    {
    for (int y=0;y<=x;++y)
    {
    std::cout<<"*";
    }
    }

  6. #6
    Compulsive Liar Robc's Avatar
    Join Date
    Jul 2004
    Posts
    149
    >wow..i actually did it.
    Congratulations. That's a good solution too. Well done, and I hope you had enough fun doing it to keep going with C++.

    >I hope no one minds me posting my code here
    No one ever minds seeing code. In fact, that's a good way to get critiques from very knowledgeable programmers. You can show off , help people who search the boards with a similar problem, and help yourself improve by putting your code out to be checked by many eyes. Provided you have a strong constitution (some people can be vicious in nitpicking code), you can learn a great deal.

  7. #7
    Registered User
    Join Date
    Feb 2004
    Posts
    35
    Quote Originally Posted by Robc
    No one ever minds seeing code.
    Apparantly, that only applies to CODE tagged code

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    5

    can you guys please tell me what i did wrong here?

    hey guys i have been an avid reader of the forums here but havnt gotten a membership until now becuase i had this problem that has puzzled me. i was working on modifying this program to go in a decreasing fashion. i couldnt do it hardcoded or with user defined variables. i dont know why it wasnt working probibly some really big flaw that i missed as a newb.



    Code:
    #include <iostream>
    #include <stdlib.h>
    
    
    using namespace std;
    
    
    int star(int x)
    {
        for (int y=1;y<=x;++x)
        {
        cout<<"*";}
        }
    int negastar(int x)
    {
        for (int y=1;x>y;x-1)
      {
         cout<<"*";
      }    
    }
    
    
    int main()
    {
    int x;
    for (x=0;x<10;x++)
        {
        star(x);
        cout<<"\n";
        }
    while(x>1)
    {
        negastar(x);
        cout<<"\n";
    }
    system("pause");
    return 0;
    }

    im using dev-c++ from bloodshed with the latest updates and everything and i dont think its a software problem. thanks for all the help in advance

  9. #9
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    This should do what you want
    eg.
    Code:
    #include <iostream>
    using namespace std;
    
    int star(int x)
    {
      for(int y=0;y<x;y++)
      {
        cout<<"*";
      }
      return 0;
    }
    int backstar(int x)
    {
      for (int y=0;x>y;x--)
      {
        cout<<"*";
      }
      return 0;
    }
    
    int main()
    {
      for (int x=0;x<10;x++)
      {
        star(x);
        cout<<endl;
      }
      for (int x=10;x>0;x--)
      {
        backstar(x);
        cout<<endl;
      }
      getchar();
      return 0;
    }
    Last edited by prog-bman; 07-17-2004 at 08:40 PM.
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM