User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,481 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,802 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2134 | Replies: 19 | Solved
Reply
Join Date: Jul 2005
Posts: 1,288
Reputation: Lerner is just really nice Lerner is just really nice Lerner is just really nice Lerner is just really nice 
Rep Power: 9
Solved Threads: 175
Lerner Lerner is offline Offline
Nearly a Posting Virtuoso

Re: C++ questions

  #11  
Oct 31st, 2006
There's often more than one way to solve a programming problem. joeprogrammer is sending you down one road, and Ancient Programmer down the other. Unless you understand what the loops are doing however, it won't matter which road you take.

In your second program you don't want to print out x, that will just give you 9s on the first line, 8s on the second etc. Instead you want to print from 1 to x, which could be the value y, if you set up the second loop right by understanding what you are trying to do, by writing it down, etc.
Reply With Quote  
Join Date: Oct 2006
Posts: 35
Reputation: JS1988 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
JS1988 JS1988 is offline Offline
Light Poster

Re: C++ questions

  #12  
Oct 31st, 2006
yeah I got how to reverse the first loop it was the second one that is confusing me still. I should made that clear when I posted
Reply With Quote  
Join Date: Apr 2006
Location: Canada
Posts: 4,535
Reputation: John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light 
Rep Power: 17
Solved Threads: 283
Moderator
Featured Blogger
John A's Avatar
John A John A is online now Online
Vampirical Moderator

Re: C++ questions

  #13  
Oct 31st, 2006
You only need to reverse the second loop. (Which is sort of what I was trying to say before.) Thus, your loops would look like this:
  1. for(int x = 9;x>=1;x--)
  2.  
  3. {
  4.  
  5. for(int y = 1;y<=x;y++)
  6.  
  7. cout<<y;
  8.  
  9. cout<<endl;
  10.  
  11. }
  12. }
Last edited by John A : Oct 31st, 2006 at 8:51 pm.
tuxation.com - Linux articles, tutorials, and discussions
Reply With Quote  
Join Date: Oct 2006
Posts: 35
Reputation: JS1988 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
JS1988 JS1988 is offline Offline
Light Poster

Re: C++ questions

  #14  
Oct 31st, 2006
Ok now i see....so if i want to make *'s appear now i should have to change the int to char but then i dont see how you get them to print because it isn't the same as with the numbers is it.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: C++ questions

  #15  
Oct 31st, 2006
Originally Posted by JS1988 View Post
yeah I got how to reverse the first loop it was the second one that is confusing me still. I should made that clear when I posted


Like Mr. Lerner said there, unless you yourself understand what looops are and how they function, it would be a tough time for you.

Just keep in mind that the inner for loop is executed outer for loop number of times.

For each iteration of outer loop,
Run the entire inner loop.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Apr 2006
Location: Canada
Posts: 4,535
Reputation: John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light 
Rep Power: 17
Solved Threads: 283
Moderator
Featured Blogger
John A's Avatar
John A John A is online now Online
Vampirical Moderator

Re: C++ questions

  #16  
Oct 31st, 2006
I gave you the answer to one of your homework questions. Now, can't you figure out how to do the rest? Loops are difficult, and it's because they execute a lot of instructions in a small amount of code.

~s.o.s~ explained loops very well, and if you want to know more, you should read up on them (use Google).
tuxation.com - Linux articles, tutorials, and discussions
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: C++ questions

  #17  
Oct 31st, 2006
Just replace the y in cout with your character.

  1. char mychar = '*' ; // this is how we declare and initialize characters
  2.  
  3. // your loops here
  4. cout << mychar ;
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

Re: C++ questions

  #18  
Nov 1st, 2006
Here's the code for the first problem:
#include <iostream>

using namespace std;

int main()
{
    int num;
    do
    {
        cout << "Enter a number > 0: ";
        cin >> num;
    } while (num <= 0);


    for (int j=num; j>0; j--)
    {
        for (int i=1; i<=j; i++)
            cout << i << " ";
        cout << endl;
    }

    cout << endl;
    return 0;
}
Reply With Quote  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

Re: C++ questions

  #19  
Nov 1st, 2006
The second one:
#include <iostream>

using namespace std;

int main()
{
    for (int i=0; i<11; i++)
        cout << '=';
    cout << endl;

    for (i=0; i<5; i++)
    {
        for (int j=0; j<2; j++)
        {
            cout << "*";
        }
        cout << endl;
    }
    
    for (i=0; i<11; i++)
        cout << '=';
    cout << endl;

    return 0;
}
Reply With Quote  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

Re: C++ questions

  #20  
Nov 1st, 2006
And third:
#include <iostream>

using namespace std;

int main()
{
    int num;
    cout << "Enter a number > 0: ";
    cin >> num;

    for (int j=num; j>0; j--)
    {
        for (int i=j; i>0; i--)
            cout << "*";
        cout << endl;
    }

    cout << endl;
    return 0;
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 2:52 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC