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;
}
|