Thread: Coin counting (logic problem)

  1. #46
    Registered User
    Join Date
    Jan 2005
    Posts
    18
    Ok I have one little problem and that's all I'm asking out of these forums (for now at least)!

    I have a project that I have to do, you have to display this with loops:

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

    Now you can't just write
    Code:
    cout << "*\n";
    cout << "**\n";
    etc.
    I'm supposed to write it with loops. This is all I have so far, and all I can get is a row of *'s going vertical :\ Sorry for asking so many questions, but it's probably a simple project, I've just never done anything like this before.
    Code:
    #include <iostream.h>
    #include <stdio.h>
    
    main()
    {
          int asterisks = 0; 
          do
          {
          cout << "*\n"; 
          asterisks++;
          }
          while (asterisks < 6);
          getchar();getchar();
          return 0;
    }

  2. #47
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Why don't you look into using for()?

    Code:
    for (int x = 0; x < MAX_STARS; x++)
    {
        // Your code for handling the loop here
    }


    Edit: I'll be nice and give another hint.

    Your life will be a lot easier if you insert a while() loop into your for() loop. Allow me yet another example.

    Code:
     #define MAX_STARS 6
    
    // int main() stuff..
    
    int y = 0;
    
    for (int x = 0; x < MAX_STARS; x++)
    {
        while (y <= x)
        {
            // Handle your std::cout and y increment here
        }
    }


    Edit 2: I just played around with code for a second and made up a function to do something like this:

    *
    **
    ***
    ****
    *****
    ******
    *****
    ****
    ***
    **
    *
    Only go to the following link if you are truly and completely stumped on the problem: http://lithorien.net:5001/test.cpp
    Last edited by Lithorien; 01-19-2005 at 09:42 PM.

  3. #48
    Registered User
    Join Date
    Jan 2005
    Posts
    18
    Actually, for the test that was today, there were 3 programs I had to know, and one of them would be on the test. Thankfully, one of the three programs on it was the one I knew (the asterisks one being the 3rd the one i didnt know). So I don't need it anymore, thanks for the help anyway D:
    Looks simpler than I thought.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Josephus problem variant logic troubles
    By misterMatt in forum C++ Programming
    Replies: 0
    Last Post: 04-29-2009, 02:38 PM
  2. Replies: 5
    Last Post: 01-31-2006, 01:54 AM
  3. Logic problem?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-10-2002, 04:10 PM
  4. Problem with letter and word counting
    By wordup in forum C Programming
    Replies: 3
    Last Post: 10-09-2002, 04:02 PM