countdown...BLAST OFF!!!
May 5, 2011 at 4:37am UTC
--------------------------------------------------------------
4. Write the C++ statements that will print the following:
.9---------
..8--------
...7-------
....6------
.....5-----
......4----
.......3---
.......2--
........1-
BLAST OFF!!!
(dots are spaces)
Make sure that you use a loop (preferably nested ones) .
--------------------------------------------------------------
Im trying to get ready for test tomorrow and this problem i just know how to do it, freaking thing just wont work... help please
thats the closest i gotten to making this work
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include<iostream>
using namespace std;
#include <string>
#include <iomanip>
int main()
{
int count;
cin>>count;
int spaces;
spaces=1;
while (count!=0)
{
cout<< setfill(' ' )<<setw(spaces);
cout<<count<<setfill('-' )<<setw(count)<<endl;
count--;
spaces++;
}
}
Last edited on May 5, 2011 at 4:55am UTC
May 5, 2011 at 4:59am UTC
you need the other loops in it to make it work. Remember you said nested ones....
1 2 3 4 5 6 7 8 9 10 11 12 13
while (count!=0)
{
for (nIndex = 0; nIndex < spaces; nIndex++)
cout << "." ;
cout<<count;
for (nIndex = count; nIndex > 0; nIndex--)
cout << "-" ;
cout << endl;
count--;
spaces++;
}
Topic archived. No new replies allowed.