#include <iostream>
usingnamespace std;
int main( int argc, char **argv )
{
int num;
cout << "Enter a number: ";
cin >> num;
// You might want to add code to validate the number here
do
{
for( int i = 0; i < num; i++ )
cout << num;
cout << endl;
} while ( num-- );
return 0;
}
hi hmm.. is there a way i can do this using do while loop only?.. i want to use do while loop only on this project but i dont know how to do it, all ive got is the reverse one, ive been trying to manipulate the code for more than 5 hours now. and im all stress out.. can you give me a hint?.. or explain the logic regarding it.. thanks a bunch if you may..
Not really just a do-while loop, no. At least not in a sensible way I can think of.
You could use a do-while with another while inside of it, replacing my for loop with a while. Or you could do a do-while with a switch or if statement inside of it.
If you're using functions you could use some sort of recursive method, I guess. It might hurt your head a bit, though.
#include <iostream>
usingnamespace std;
void RecursivePrint( int num, int count )
{
if( !count )
cout << "\n";
else
{
cout << num;
RecursivePrint( num, --count );
}
}
int main( int argc, char **argv )
{
int num;
cout << "Enter a number: ";
cin >> num;
// You might want to add code to validate the number here
do
{
RecursivePrint( num, num );
} while ( num-- );
return 0;
}
hi iHutch thank you so much i figured it out already thanks for first sample i just put some 3 variables and one is validation and so on... thank you very much.. until nexttime :) ill wait 24hours before i closed this thread.