Use a looping structure to create C++ program that outputs 10 9 8 7 6 5 4 3 2 1 Blast off!

I'm having a hard figuring an assignment out. I'm very new to C++, so any help would be appreciated. I'm supposed to use a looping structure(for, do while, while) to create a C++ program that outputs "10 9 8 7 6 5 4 3 2 1 Blast off!". Part of the assignment is to put the numbers on each line. I know how to create a few loops, but I can't find any examples of a problem like this. There aren't any in my text book. Here's what I did come up with, but I have a feeling it's not even close to what I'm supposed to have. If you know what this problem specifically asks for, any help would be appreciated..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 #include <iostream> 
int main()
{
   char s[] = "10 9 8 7 6 5 4 3 2 1 Blast off!";
   const int N = 5;

   for ( int i = 0; i < N; i++ )
   {
      for ( char *p = s; *p; ++p ) std::cout << *p;
      std::cout << std::endl;
   }

   return 0;
}
closed account (Dy7SLyTq)
1
2
3
4
5
int i = 11;
while(--i > 0)
     cout<< i <<" ";

cout<<"BLAST OFF!"<< endl;
for using a for loop.
1
2
3
4
5
6
7
  for ( int i = 10; i > 0; i-- )
    {
        std::cout << i << std::endl;
    }

    std::cout << "BLAST OFF"<< std::endl;
Yeah I wouldn't use a char array.

1. create a variable that and assign it the value 10.

2. Create a for loop that de-increments the variable after running, so it will print 10 before decreasing to 9.

3. In that for loop simply have it print the variable and have endl; after the statement.

4. Use an if statement to check when it's finished the count down. When it confirms that it is simply tell it to print "Blast off!".

However, you're assignment wishes for you to use a while loop. In that case...

1. Create a variable and assign it the value 10.

2. Create a while loop that will run as long as the variable is greater than 0.

3. Inside the while loop, tell it to print the variable with an endl; on the end of the statement.

4. Under that have it post-de-increment.

Since you seem to have actually tried I'll just post the code as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>

int main(){
    int x = 10;

    while(x > 0){
        std::cout << x << std::endl;
        x -= 1;
    }

    std::cout << "Blast off!" << std::endl;

    return 0;
}
Thanks for the help guys. I appreciate it..
Topic archived. No new replies allowed.