CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2017
    Posts
    182

    [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 offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. 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/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    May 2017
    Posts
    182

    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
    182

    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
    Hanover Germany
    Posts
    20,396

    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 offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. 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/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    May 2017
    Posts
    182

    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
  •  





Click Here to Expand Forum to Full Width

Featured