-
June 30th, 2017, 05:18 AM
#1
[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 ...
-
June 30th, 2017, 06:32 AM
#2
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)
-
June 30th, 2017, 06:37 AM
#3
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.
-
June 30th, 2017, 06:58 AM
#4
Re: join to piece of a program
I have another question on single character validation can I ask about it ??
-
June 30th, 2017, 07:13 AM
#5
Re: join to piece of a program
Originally Posted by david16
I have another question on single character validation can I ask about it ??
Why not? Ask!
Victor Nijegorodov
-
June 30th, 2017, 11:19 AM
#6
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)
-
June 30th, 2017, 12:33 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|