•
•
•
•
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
![]() |
•
•
Join Date: Jul 2005
Posts: 1,288
Reputation:
Rep Power: 9
Solved Threads: 175
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.
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.
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:
c Syntax (Toggle Plain Text)
for(int x = 9;x>=1;x--) { for(int y = 1;y<=x;y++) cout<<y; cout<<endl; } }
Last edited by John A : Oct 31st, 2006 at 8:51 pm.
tuxation.com - Linux articles, tutorials, and discussions
•
•
•
•
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.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
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).
~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
Just replace the y in cout with your character.
c Syntax (Toggle Plain Text)
char mychar = '*' ; // this is how we declare and initialize characters // your loops here 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.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Rep Power: 3
Solved Threads: 2
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;
}•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Rep Power: 3
Solved Threads: 2
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;
}•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Rep Power: 3
Solved Threads: 2
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;
}![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Questions about Forum (Geeks' Lounge)
- I have a few questions to be patched up can anybody get these to me ? (C++)
- Preparing for an interview and need some questions answered (C)
- Wireless Questions (Networking Hardware Configuration)
- Linux printing questions (*nix Hardware Configuration)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: New object initialization error
- Next Thread: How to load dll files in Microsoft Visual C++?



Linear Mode