C++ problem

This is a discussion on C++ problem within the C++ Programming forums, part of the General Programming Boards category; How can I write a program that when I input a five-digit number, it'll help me to separates the number ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    101

    C++ problem

    How can I write a program that when I input a five-digit number, it'll help me to separates the number into its individual digits and prints the digits separated from one another by three spaces each by using the integer division and modulus operators? thx!~

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    this will get you started. I'm not sure what you wanted with the modulas division. But if you want to operate on these values you'll have to use the atoi c runtime function.


    Code:
    #include "stdafx.h"
    #include <iostream> 
    using namespace std;
    
    int main() { 
    
    	char szNum[6];
    
    	cout << "Please enter a 5 digit number and <enter> : ";
    	cin >> szNum;
    
    	for( int i = 0; i < 5;i++ )
    	{
    		cout << szNum[ i ] << "   ";
    	}
    
    	cout << endl;
    
    	return 0; 
    } // end

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    25
    For error detection I would write code to ensure that all the digits are initilized into the array. Example if input is 123 the char array should be filled with 00123\n instead of 123/n(random value) (random value).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21