C++: Countdown With "for" Loop
C++ program that counts down from a number that the user enters.
#include <iostream>
#include <string>
using namespace std;
int main()
{ // start main function
int alpha;
int countdown;
cout << "Enter number to countdown from: ";
cin >> countdown;
for (alpha=0; alpha<=countdown; countdown--)
{
cout << "Countdown at: " << countdown << endl;
if (countdown==0)
cout << "Liftoff!";
} // end for loop
return 0;
} // end main function
Downloads
Supplies
- Desktop or laptop computer.
- Code::Blocks IDE for C++ programming.
C++ Program That Counts Down From a Number That a User Enters
C++ program that counts down from a number that the user enters.
using namespace std;
int main()
{ // start main function
int alpha;
int countdown;
cout << "Enter number to countdown from: ";
cin >> countdown;
for (alpha=0; alpha<=countdown; countdown--)
{
cout << "Countdown at: " << countdown << endl;
if (countdown==0)
cout << "Liftoff!";
} // end for loop
return 0;
} // end main function