code a c++ program

hello guys.i would like to code this program. i just got confused how to do it. any help?. thanks

input a four digit integer

while integer > 0

               

                divide integer by 1000 to get temp

                add 7 to temp

                divide (modulus) temp by 10 to get new first digit

 

                divide (modulus) integer by 1000 to get temp

                divide temp by 100

                add 7 to temp

                divide (modulus) by 10 to get new second digit

 

                divide (modulus) integer by 1000 to get temp

                divide (modulus)temp by 100

                divide temp by 10

                add 7 to temp

                divide (modulus) by 10 to get new third digit

 

                divide (modulus) integer by 1000 to get temp

                divide (modulus) temp by 100

                divide (modulus) temp by 10

                add 7 to temp

                divide (modulus) by 10 to get new fourth digit

 

                set temp to new first digit                                                                  

                multiply new third digit by 1000 to get first

                multiply temp by 10 to get third

 

                set temp to new second digit                                                        

                multiply new fourth digit by 100 to get new second digit

                set fourth digit to temp

 

                add first, second, third, fourth to get encrypted number

 

output encrypted number

 

                input four digit integer
FRANCOIS_DUQUESNEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Deepu AbrahamR & D Engineering ManagerCommented:
to divide use operator '/' and for mod use operator '%'
0
Infinity08Commented:
You pretty much laid out in pseudo code what you want to do. Now it's just a matter of transforming it into code.

Are there any specific pseudo code lines you have a problem with ?

Did you give this a try yet ? If so, can you show us ?
0
FRANCOIS_DUQUESNEAuthor Commented:
hi guys. i was reaaly confuse on this problem. i didn't know how to start. especially with the modulus things made it more confusing to me. here all what i have done

# include <iostream.h>
int main()
{
input a four digit integer

while integer > 0

               

                divide integer by 1000 to get temp

                temp= 7 +temp;//add 7 to temp

                divide (modulus) temp by 10 to get new first digit

 

                divide (modulus) integer by 1000 to get temp

                temp/100;//divide temp by 100

                temp= 7+ temp;//add 7 to temp

                divide (modulus) by 10 to get new second digit

 

                divide (modulus) integer by 1000 to get temp

                divide (modulus)temp by 100

                temp/100; //divide temp by 10

                temp= 7+ temp; //add 7 to temp

                divide (modulus) by 10 to get new third digit

 

                divide (modulus) integer by 1000 to get temp

                divide (modulus) temp by 100

                divide (modulus) temp by 10

                temp= 7 + temp;//add 7 to temp

                divide (modulus) by 10 to get new fourth digit

 

                set temp to new first digit                                                                  

                multiply new third digit by 1000 to get first

                multiply temp by 10 to get third

 

                set temp to new second digit                                                        

                multiply new fourth digit by 100 to get new second digit

                set fourth digit to temp

 

                encrypted_number= first + second + third + fourth;// get encrypted number

 

cout<<"\n encrypted_number= " <<encrypted_number;// output encrypted number
   return 0;
}
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Infinity08Commented:
That's a good start. Just a small comment on the code you have : <iostream.h> is deprecated. You should use <iostream>

Now, some hints to continue :

1) for "input a four digit integer", check out this tutorial on basic input/output in C++ :

        http://www.cplusplus.com/doc/tutorial/basic_io.html

    there are several examples and explanations on that page that should help you forward.


2) for "while integer > 0", check out this tutorial on control structures in C++ :

        http://www.cplusplus.com/doc/tutorial/control.html

    (scroll down to "the while loop"). Again lots of examples and explanations.


3) integer division is achieved with the operator /, and modulo with the operator %. More information on this page :

        http://www.cplusplus.com/doc/tutorial/operators.html



These three hints should allow you to convert more of the pseudo code into real code. Give it a go, and post your results here.

btw, I would advise you to read the rest of that tutorial too : it's a very good read when you're starting out in C++ :

        http://www.cplusplus.com/doc/tutorial/
0
FRANCOIS_DUQUESNEAuthor Commented:
thanks infinity08 for your help.. here what i have so far
# include <iostream>
using namespace std;
int main()
{
int temp, first, second, third, fourth;
int new_first_digit, new_second_digit;
int new_third_digit, new_fourth_digit;
int a,b,c,d;
cin>>a>>b>>c>>d; // input a four digit integer
while (a,b,c,d > 0)
{

               

                Temp=a/1000; //divide integer by 1000 to get temp

                temp= 7 +temp; //add 7 to temp

                new_first_digit= temp % 10; // divide (modulus) temp by 10 to get new first digit

 

                temp= b % 1000; // divide (modulus) integer by 1000 to get temp

                temp= temp/100;// divide temp by 100

                temp= 7+ temp;//add 7 to temp

               new_second_digit= b %10;// divide (modulus) by 10 to get new second digit

 

                temp= c%1000; // divide (modulus) integer by 1000 to get temp

                temp= temp %100;//divide (modulus)temp by 100

                temp= temp/100; //divide temp by 10

                temp= 7+ temp; //add 7 to temp

                new-third_digit=c %10;//divide (modulus) by 10 to get new third digit

 

                temp= d%1000; //divide (modulus) integer by 1000 to get temp

                temp= temp % 100;//divide (modulus) temp by 100

                temp= temp%10;//divide (modulus) temp by 10

                temp= 7 + temp;//add 7 to temp

                new_fourth_digit= d%10; // divide (modulus) by 10 to get new fourth digit

 

               temp=new_first_digit;// set temp to new first digit                                                                  

                first= new_third_digit * 1000;// multiply new third digit by 1000 to get first

               third= temp * 10;// multiply temp by 10 to get third

 

               temp=new_second_digit;// set temp to new second digit                                                        

                new_second_digit= new_fourth_digit*100;// multiply new fourth digit by 100 to get new second digit

               fourth=temp; // set fourth digit to temp

 

                encrypted_number= first + second + third + fourth;// get encrypted number

       }

cout<<"\n encrypted_number= " <<encrypted_number;// output encrypted number
   return 0;
}
0
Infinity08Commented:
1) for the input :

        cin>>a>>b>>c>>d; // input a four digit integer

    This will input 4 integers, not a 4-digit integer.
    You'll need to let the user input one integer, and then you'll have to verify that it's a 4-digit one.

    Notice that this change will mean that all uses of a, b, c and d should become a.


2) variable names in C++ are case sensitive. For example, "Test" is not the same as "test". Check this line for example :

        Temp=a/1000; //divide integer by 1000 to get temp


3) This line :

        temp= temp/100; //divide temp by 10

    look closely for a difference between the pseudo code and the C++ code you used.


4) - is not the same as _. Check this line :

        new-third_digit=c %10;//divide (modulus) by 10 to get new third digit


5) the lines where you extract the digits need to work on temp. I'm talking about these lines :

        new_second_digit= b %10;// divide (modulus) by 10 to get new second digit
        new-third_digit=c %10;//divide (modulus) by 10 to get new third digit
        new_fourth_digit= d%10; // divide (modulus) by 10 to get new fourth digit

    the one you made for the first digit was correct :

        new_first_digit= temp % 10; // divide (modulus) temp by 10 to get new first digit


6) this line :

        encrypted_number= first + second + third + fourth;// get encrypted number

    is most likely not correct. But we'll work on that later, once the rest of the program is working.


Please make the above modifications.
0
FRANCOIS_DUQUESNEAuthor Commented:
thanks buddy. i made all the modifications that you told me about. i feel embarassed that i didn't pay attention about the four digit integer.
# include <iostream>
using namespace std;
int main()
{
int temp, first, second, third, fourth;
int new_first_digit, new_second_digit;
int new_third_digit, new_fourth_digit;
int a;
cout<< "\n enter a four digit integer \n";
cin>>a; // input a four digit integer
while (a > 0)
{

               

                temp=a/1000; //divide integer by 1000 to get temp

                temp= 7 +temp; //add 7 to temp

                new_first_digit= temp % 10; // divide (modulus) temp by 10 to get new first digit

 

                temp= a% 1000; // divide (modulus) integer by 1000 to get temp

                temp= temp/100;// divide temp by 100

                temp= 7+ temp;//add 7 to temp

               new_second_digit= temp %10;// divide (modulus) by 10 to get new second digit

 

                temp= a%1000; // divide (modulus) integer by 1000 to get temp

                temp= temp %100;//divide (modulus)temp by 100

                temp= temp/10; //divide temp by 10

                temp= 7+ temp; //add 7 to temp

                new_third_digit=temp %10;//divide (modulus) by 10 to get new third digit

 

                temp= a%1000; //divide (modulus) integer by 1000 to get temp

                temp= temp % 100;//divide (modulus) temp by 100

                temp= temp%10;//divide (modulus) temp by 10

                temp= 7 + temp;//add 7 to temp

                new_fourth_digit= temp%10; // divide (modulus) by 10 to get new fourth digit

 

               temp=new_first_digit;// set temp to new first digit                                                                  

                first= new_third_digit * 1000;// multiply new third digit by 1000 to get first

               third= temp * 10;// multiply temp by 10 to get third

 

               temp=new_second_digit;// set temp to new second digit                                                        

                new_second_digit= new_fourth_digit*100;// multiply new fourth digit by 100 to get new second digit

               fourth=temp; // set fourth digit to temp

 

                encrypted_number= first + second + third + fourth;// get encrypted number

       }

cout<<"\n encrypted_number= " <<encrypted_number;// output encrypted number
   return 0;
}
0
Infinity08Commented:
                new_second_digit= new_fourth_digit*100;// multiply new fourth digit by 100 to get new second digit

I think the above line was a mistake in the pseudo code, and should have been :

                second= new_fourth_digit*100;// multiply new fourth digit by 100 to get new second digit
0
Infinity08Commented:
And declare encrypted_number as an int. Then try to compile, and watch the result :)
0
FRANCOIS_DUQUESNEAuthor Commented:
ok . i did compile and execute it. there was no errors at all. but when i execute =d it. the black box appeared and ask me to enter four digit number so i did and nothing happened then.
0
FRANCOIS_DUQUESNEAuthor Commented:
that's what i have

# include <iostream>
using namespace std;
int main()
{



int temp, first, second, third, fourth;
int new_first_digit, new_second_digit;
int new_third_digit, new_fourth_digit;
int encrypted_number;
int a;
cout<< "\n enter a four digit integer \n";
cin>>a; // input a four digit integer
while (a > 0)
{

               

                temp=a/1000; //divide integer by 1000 to get temp

                temp= 7 +temp; //add 7 to temp

                new_first_digit= temp % 10; // divide (modulus) temp by 10 to get new first digit

 

                temp= a% 1000; // divide (modulus) integer by 1000 to get temp

                temp= temp/100;// divide temp by 100

                temp= 7+ temp;//add 7 to temp

               new_second_digit= temp %10;// divide (modulus) by 10 to get new second digit

 

                temp= a%1000; // divide (modulus) integer by 1000 to get temp

                temp= temp %100;//divide (modulus)temp by 100

                temp= temp/10; //divide temp by 10

                temp= 7+ temp; //add 7 to temp

                new_third_digit=temp %10;//divide (modulus) by 10 to get new third digit

 

                temp= a%1000; //divide (modulus) integer by 1000 to get temp

                temp= temp % 100;//divide (modulus) temp by 100

                temp= temp%10;//divide (modulus) temp by 10

                temp= 7 + temp;//add 7 to temp

                new_fourth_digit= temp%10; // divide (modulus) by 10 to get new fourth digit

 

               temp=new_first_digit;// set temp to new first digit                                                                  

                first= new_third_digit * 1000;// multiply new third digit by 1000 to get first

               third= temp * 10;// multiply temp by 10 to get third

 

               temp=new_second_digit;// set temp to new second digit                                                        

                second = new_fourth_digit*100;// multiply new fourth digit by 100 to get new second digit

               fourth=temp; // set fourth digit to temp

 

                encrypted_number= first + second + third + fourth;// get encrypted number

       }

cout<<"\n encrypted_number= " <<encrypted_number;// output encrypted number
   return 0;
}


               
0
Infinity08Commented:
>> the black box appeared and ask me to enter four digit number so i did and nothing happened then.

Did you press ENTER after giving the number ?

If so, did the black window disappear ?

If the black window disappeared, just add this before the return 0; in your main :

        int main(void) {
            // your code

            system("PAUSE");
            return 0;
        }

and add this include at the top :

        #include <cstdlib>

Doing this will avoid that the program closes before you can see its output.
0
FRANCOIS_DUQUESNEAuthor Commented:
yes i did press enter
the black box didn't disappear
0
FRANCOIS_DUQUESNEAuthor Commented:
ok infinity 08. it 's almost 5 a.m . it is time to go to bed. thanks for everyting i will catch you later.
0
Infinity08Commented:
Ok, here are still a few problems with your code :

1) You have a space between # and include here :

        # include <iostream>

    remove that space !

2) You didn't implement your whole pseudo code, and because of that you got into an infinite loop. I'm talking about this part at the end :

                add first, second, third, fourth to get encrypted number

                output encrypted number

                input four digit integer

    Note that all of this has to be INSIDE the while loop !!
    You can end the program by entering 0 when asked to enter the number.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FRANCOIS_DUQUESNEAuthor Commented:
hello infinity08. i put it inside the loop and it did work. that's great. thanks so much.so now we have one problem down.
FRANCOIS
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.