[RESOLVED] join to piece of a program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] join to piece of a program

  1. #1
    Join Date
    May 2017
    Posts
    173

    [RESOLVED] join to piece of a program

    hello there . I have a program that is not displaying any result . I would appreciate your help . SO this is my code below
    to be clear I should do this :

    a) Calculate the integer part of the quotient when integer a is divided by integer b.
    b) Calculate the integer remainder when integer a is divided by integer b.
    c) Use the program pieces developed in (a) and (b) to write a function that inputs an
    integer between 1 and 32767 and prints it as a series of digits, each pair of which is
    separated by two spaces. For example, the integer 4562 should print as follows:
    4 5 6 2

    this is my code where I should join part a and part b to split digits :

    Code:
     #include < iostream >
    using namespace std;
    
    int quotient ( int a , int b ) // first piece.
    {
    	return a / b ;
    }
    
    int remainder ( int a, int b ) // second piece.
    {
    	return a % b;
    }
    
    void split ( int a ) // problem probably with joining them 
    {
    	int div = 10000; // since the max number of digits is 5.
    	
    	int sep; 
    
    	bool lastdigit = false; // it will stop on last non zero digit to the left.
    
    
        	while ( div != 1 )
    	{
    		sep = quotient( a , div );
    
    		if ( lastdigit == false && sep == 0 ) // if 0 do nothing.
    		{
    			
    		}
    		else
    		{
    			lastdigit = true;
    			cout << sep << "  ";
    		}
    
    		a = remainder( a , div  );
    		div = div / 10;
     	}
    
    	cout << a << endl;
    }
     
    
    int main ()
    {
    	int x;
    
    	
    	cout << "\nThis program will split a number of your choice between the following range : \n " << endl;
    	
    	do {
    		 cout << "\nPlease enter an interger number X ( 1 < X < 32767 ) :\n " << endl; 
    		 cin >> x;
    
    	}while ( x < 1 && cout << "\nSorry wrong input!\n" ||  x > 32767 && cout << "\nSorry wrong input!\n" ); 
    
    
    	void split ( int x );
    
    
        cout << "\n";
    	system ( "pause" );
    	return 0;
    
    }

    thanks for your help ...

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,580

    Re: join to piece of a program

    Code:
    void split ( int x );
    Do you mean to declare a function split here?
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  3. #3
    Join Date
    May 2017
    Posts
    173

    Re: join to piece of a program

    Oh I see I have t pit split ( x ) ; I didnt notice that . thx
    Last edited by david16; June 30th, 2017 at 06:52 AM.

  4. #4
    Join Date
    May 2017
    Posts
    173

    Re: join to piece of a program

    I have another question on single character validation can I ask about it ??

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,925

    Re: join to piece of a program

    Quote Originally Posted by david16 View Post
    I have another question on single character validation can I ask about it ??
    Why not? Ask!
    Victor Nijegorodov

  6. #6
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,580

    Re: [RESOLVED] join to piece of a program

    Last edited by 2kaud; June 30th, 2017 at 01:14 PM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  7. #7
    Join Date
    May 2017
    Posts
    173

    Re: [RESOLVED] join to piece of a program

    I'll post a new thread please join on it. this name "join to piece of a program 2"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)