C++: Countdown With "for" Loop

by matt392 in Circuits > Software

5 Views, 0 Favorites, 0 Comments

C++: Countdown With "for" Loop

countdown1.jpg
countdown3.jpg

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

Supplies

codeblockslogo.png
desktopcomputer.jpg
c++image.jpg
  1. Desktop or laptop computer.
  2. Code::Blocks IDE for C++ programming.

C++ Program That Counts Down From a Number That a User Enters

countdown2.jpg

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