Requests a name, prints the name five times, and rings a bell. - C++ Language Basics

C++ examples for Language Basics:Console

Description

Requests a name, prints the name five times, and rings a bell.

Demo Code

#include <iostream>
using namespace std;
int main()//from w  w w  .j a  v a 2  s.c o  m
{
   const char BELL = '\a';      // Constant that rings the bell
   int ctr = 0;       
   char fname[20];    
   cout << "What is your first name? ";    // Prompt the user
   cin >> fname;      
   while (ctr < 5)
   {
      cout << fname << "\n";
      ctr++;
   }
   cout << BELL;                  // Ring the terminal's bell
   return 0;
}

Result


Related Tutorials