Need help

This is a discussion on Need help within the C++ Programming forums, part of the General Programming Boards category; I need to write a program that inputs from the user a positive integer, say n, and any character, say ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    18

    Need help

    I need to write a program that inputs from the user a positive integer, say n, and any character, say c, and outputs to a file called "ass2.run" a solid isosceles triangle constructed with the character c, with its sides of size n and its right angle at the lower right corner. For example, if the inputs were 6 and the character "*" , the output file woulf look like:

    Triangle: n=6, character =*
    *
    **
    ***
    ****
    *****
    ******
    He gaves us a hint, for each line, output the needed number of blanks and then the needed number of characters. use a two for loops(one for the blanks and one for the charater) inside another for loop.
    Basically he wants a

    For
    [

    For
    [
    For

    Loop

    He also taught us how to output the file using infile ; and outfile ; commands. Please keep the language simple as possible. Thanks for the help

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You seem to already know to use two nested for loops and how to output stuff. So what's the problem?
    If you're stuck then post the code you got and the exact part you need help with, not posting your assignment.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Your output should look like this, right?
    Code:
         *
        **
       ***
      ****
     *****
    ******
    The spaces get messed up if you don't use [code] tags.

    I would suggest writing a simple program that asks the user for n and for c. Then write a separate simple program that writes something to an output file. Then write a separate simple program that writes the triangle above (with c='*' and n=6) to cout. Then once all three are working, combine each part one at a time into a big program.

    Good luck and post code if you've tried but still can't figure a specific problem out.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21