Makes a number out of digits - C++ Data Type

C++ examples for Data Type:int

Description

Makes a number out of digits

Demo Code

#include <iostream>
using namespace std;
#include <conio.h>                   //for getche()
int main()/* ww w . j  a va 2  s .co m*/
{
   char ch;
   unsigned long total = 0;          //this holds the number
   cout << "\nEnter a number: ";
   while( (ch=getche()) != '\r' )    //quit on Enter
      total = total*10 + ch-'0';     //add digit to total*10
   cout << "\nNumber is: " << total << endl;
   return 0;
}

Result


Related Tutorials