Click here to Skip to main content
13,301,100 members (81,963 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 31 May 2010

Rread a number input from the keyboard and then put each of its components in an array

, 31 May 2010
Rate this:
Please Sign up or sign in to vote.
Description of how to read a number input from the keyboard and then put each of its components in an array
It reads a number from CMD [For example: 1234].
Then puts each of its components in an array - digitArray[3]=1, digitArray[2]=2, digitArray[1]=3, digitArray[0]=4 .

   //         one                ten              hundred              thousand
   //          1                  2                  3                    4
   //digitn=digitArray[3]*1 + digitArray[2]*10 +digitArray[1]*100 +digitArray[0]*1000
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

int digit=0,digitInput=0;
int digitArray[4]={0},digitn;
 *                               *
void getIntKey(void)
	   if (kbhit())
		   if ((digitInput>47) && (digitInput<59))
	                 digitArray[digit]=(unsigned char)digitInput-48;
		   if (digitInput==13)  { digitn=digitArray[0]; break; }
   if (digitInput!=13)  digitn=digitArray[3]*1+digitArray[2]*10+digitArray[1]*100+digitArray[0]*1000 ;
 *                               *
int main()
	system("color 1F");     //Blue background       
   printf("This program by TopCoder requires you to input 4 digits  \n ");
   printf("Input Digits  (ex. 1=0001 , 1234=1234)  \n ");
   printf("\nInput Digits    >");
   printf("\ndigitArray[3]=%d \n",digitArray[3]);
   printf("digitArray[2]=%d \n",digitArray[2]);
   printf("digitArray[1]=%d \n",digitArray[1]);
   printf("digitArray[0]=%d \n",digitArray[0]);


	return 0;



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 2 It's a bit longwinded isn't it? The ... Pin
Aescleal31-May-10 11:48
memberAescleal31-May-10 11:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 31 May 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid