| | |
Help complete typical question with for loops
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 27
Reputation:
Solved Threads: 0
the typical question which ask user to display THIS
*
**
***
****
*****
******
*******
********
*********
**********
using a single cout<<"*" & cout " " with the help of for loops ONLY.
ive come to this this prgram but can anyone tell me where i am going wrong and how to correct this error pls!!! :o
whats wrong here!!!!
THE PROBLEM CONTINUES ON.....but for now i need help till here :cry:
*
**
***
****
*****
******
*******
********
*********
**********
using a single cout<<"*" & cout " " with the help of for loops ONLY.
ive come to this this prgram but can anyone tell me where i am going wrong and how to correct this error pls!!! :o
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <conio.h> int main() { int a,b=1,c=10; for ( a=10 ; a >=0 ; a--) { for ( ; b>0 ; b--) { cout<<"*"; } for ( ; c>0 ; c--) { cout<<" "; } } getch(); return 0; }
whats wrong here!!!!
THE PROBLEM CONTINUES ON.....but for now i need help till here :cry:
•
•
Join Date: Sep 2004
Posts: 56
Reputation:
Solved Threads: 2
Oh yeah, also your b and c variables are only initialized to work the first time through. After the first run b and c are equal to zero and therefore those two nested for loops will do nothing. I am heading off to class so I can't fix the problem for you right now but that is whats going to wrong. You need to find a way to reinitialize b and c for every pass through.
•
•
Join Date: Nov 2004
Posts: 12
Reputation:
Solved Threads: 0
Hi....I am a c++ begginer and i hav a solution for ur problem of ur program...Check out the program I wrote..the program is below...Plz message me if ur problem is solved or if u want any help...
#include<iostream.h>
#include<conio.h>
void main()
{
int i, j;
for(i=0; i<10; i++)
{
for(j=0; j<=i; j++)
cout<<'*';
cout<<endl;
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int i, j;
for(i=0; i<10; i++)
{
for(j=0; j<=i; j++)
cout<<'*';
cout<<endl;
}
getch();
}
>>>Extreme<<<
•
•
Join Date: Nov 2004
Posts: 27
Reputation:
Solved Threads: 0
THANX A LOT ETXREME!!!!! :o
but as our forum admin says u shud not help people do their homework!!!
definetly ive been tempted to copy ur program..........BUT !!!!!
as jasweb pointed out i must some re-initialise b and c to one less and one greater value !!!!!........but where exactly in the loops???? :mad:
pls tach me how to do that.....coz more important than assignment marks is that i understand how to do this tpe of stuff.......
but as our forum admin says u shud not help people do their homework!!!
definetly ive been tempted to copy ur program..........BUT !!!!!
as jasweb pointed out i must some re-initialise b and c to one less and one greater value !!!!!........but where exactly in the loops???? :mad:
pls tach me how to do that.....coz more important than assignment marks is that i understand how to do this tpe of stuff.......
Just Extreme's code a little tidied up for Dev C++
Hope you can see the flow of things.
Hope you can see the flow of things.
C++ Syntax (Toggle Plain Text)
// Dev C++ code #include <iostream> using namespace std; int main() { int k, m; for(k = 1; k <= 10; k++) { // outputs 1,2,3,...,10 stars for(m = 0; m < k; m++) cout << "*"; // end each inner loop with a new line cout << endl; } cin.get(); // wait return 0; }
May 'the Google' be with you!
•
•
Join Date: Nov 2004
Posts: 27
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by vegaseat
Just Extreme's code a little tidied up for Dev C++
Hope you can see the flow of things.
C++ Syntax (Toggle Plain Text)
// Dev C++ code #include <iostream> using namespace std; int main() { int k, m; for(k = 1; k <= 10; k++) { // outputs 1,2,3,...,10 stars for(m = 0; m < k; m++) cout << "*"; // end each inner loop with a new line cout << endl; } cin.get(); // wait return 0; }
AHHH!!......so he's using the first loop variable in the test expression of the second loop!!!!!!!! :mrgreen:
NOW I GET IT!!!!!!!!!!!!!!!!!!!!!!!
![]() |
Similar Threads
- OEM PC -Windows XP Home (oem) does not complete installation-set up loops (Troubleshooting Dead Machines)
Other Threads in the C++ Forum
- Previous Thread: C++ Compilers
- Next Thread: Geting elements from a String Array
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







MOOCH: