Need help with simple programs...

This is a discussion on Need help with simple programs... within the C++ Programming forums, part of the General Programming Boards category; We're doing review of last year's programming, and I can't figure them out!! I know they have to be easy. ...

  1. #1
    BCole19
    Guest

    Need help with simple programs...

    We're doing review of last year's programming, and I can't figure them out!! I know they have to be easy. Please help me get started:

    1. Write a program that uses FOR loops to produce the following pattern:

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

    (I hope it turns out like I typed it)


    2. Used NESTED FOR LOOPS to produce the following numbering on the screen:

    1

    1
    2

    1
    2
    3

    1
    2
    3
    4

  2. #2
    BCole19
    Guest
    Okay, the first one didn't turn out like I wanted it to be, it should be a big X but with asterisks.

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    These are really easy. I could solve them both in 5 minutes... but that would take all the thinking away from you.

    Think about nested for loops, and it should become pretty clear.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  4. #4
    BCole19
    Guest

    eh

    Okay, thanks, you didn't help me at all. You see, I already know all this crap, but I forgot over the summer. Sounds stupid, but it's true.

  5. #5
    junior member mix0matt's Avatar
    Join Date
    Aug 2001
    Posts
    144
    You see, I already know all this crap, but I forgot over the summer
    eh?

    maybe you should retake the previous course. this stuff is really easy, and we're under no obligation to DO other's homework. Post some code, and show us you give half a crap...

    mxr
    THIS IS NOT JUST A CHRONICLING OF THINGS WE HAVE DONE IN THE PAST BUT OUR RISE TO POWER.

  6. #6
    BCole19
    Guest
    I have

    for (a = 0; a < 9; a++)
    {
    cout<<"*";
    }


    Nah, I don't need to take the course again. It'll come back to me hopefully.

  7. #7
    Unregistered
    Guest
    Can someone at least help me get started? I do alot better from learning from other people's code.

  8. #8
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Give a man a fish, he eats for a day.
    Teach a man to fish, he eats for a lifetime.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    Red face

    [QUOTE]Originally posted by BCole19
    [B]I have

    for (a = 0; a < 9; a++)
    {
    cout<<"*";
    }




    Here's a start. You don't have any nested for loops. You will also need to cout some blank spaces on the X problem. On part of the X you'll need to increment, on the other decrement (at least that's one way to do it).

  10. #10
    Registered User
    Join Date
    Aug 2001
    Posts
    89
    >>Give a man a fish, he eats for a day.
    Teach a man to fish, he eats for a lifetime.<<

    heeeeeeyyyyyyyy....
    good one, i did not knew that...
    behold the faithless one and his angel

  11. #11
    Registered User
    Join Date
    Aug 2001
    Posts
    89
    forgive my mistakes...i think that after "did" goes "know" and
    no "knew" ah? sorry...
    behold the faithless one and his angel

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    17

    Lightbulb

    Why dont u try the loop function.

  13. #13
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Code:
    #include<iostream>
    #define MAX 5
    
    int main()
    {
    	int i_loops;
    
    	for(int i=0; i< MAX;i++)
    	{
    		i_loops = 0;
    		while(i_loops++ < i) std::cout << ("%d",i_loops) << std::endl;
    
    		if(i != 0) std::cout << std::endl;
    	}
    	return 0;
    }
    Here is a way to do it without nested 'for' loops. HAHAHAHAHAHA
    I compile code with:
    Visual Studio.NET beta2

  14. #14
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    ("%d",i_loops) is unnecessary in c++...... you just cout<<i_loops and it will work fine.....
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  15. #15
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Yeah, I forgot about that!
    I compile code with:
    Visual Studio.NET beta2

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple 2d "putpixel" api for windows?
    By spiky in forum C Programming
    Replies: 2
    Last Post: 10-27-2005, 03:44 PM
  2. help with simple programs. Matrix multiplications
    By ovadoggvo in forum C Programming
    Replies: 1
    Last Post: 05-19-2005, 12:46 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Hints required to complete simple programs
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 06-30-2002, 10:20 PM

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