Need help plz

Need help plz

Post by shdwcat on Sun Nov 18, 2012 4:05 pm
([msg=71083]see Need help plz[/msg])

So I am writing a program that will reverse 6 integers while using a prototype. I have it to where it reverses 4 integers but when I move on to do the 5 and 6 digits it doesnt show the reverse anymore just some other numbers.

Code: Select all
#include <cstdlib>
#include <iostream>

using namespace std;

int reverse(int value);
int reverse (int argc, char *argv[]);


int main()

{ //Do not edit anything between this comment and the next comment.
    int value;
    cout << "Enter a positive integer less than 1000000: ";
    cin >> value;
    value = reverse(value);
    cout << "\nYour integer in reverse order is: " << value;
    cout << "\n\n\n";
   
    system("PAUSE");
    return EXIT_SUCCESS;
} // Do not edit anything between the previous comment and this one.


int reverse( int value)
{
     int sum = 0;
     int val;
     
/*I know 5th and 6 integers goes here but I dont know
     and cant find formula to reverse 5th and 6th any help plz*/

     
     val = value / 1000;
     sum = val;
     value = value - (val * 1000);

     val = value / 100;
     sum = sum + (val * 10);
     value = value - (val * 100);

     val = value / 10;
     sum = sum + (val * 100);
     value = value - (val * 10);

     sum = sum + (value * 10000);

return(sum);
}


-- Sun Nov 18, 2012 4:53 pm --

nvm all I figured it out I replaced

Code: Select all
int sum = 0;
     int val;
     
/*I know 5th and 6 integers goes here but I dont know
     and cant find formula to reverse 5th and 6th any help plz*/

     
     val = value / 1000;
     sum = val;
     value = value - (val * 1000);

     val = value / 100;
     sum = sum + (val * 10);
     value = value - (val * 100);

     val = value / 10;
     sum = sum + (val * 100);
     value = value - (val * 10);

     sum = sum + (value * 10000);

return(sum);





With

Code: Select all
int rev, val;


     while (value > 0)
     {
           val = value % 10;
           rev = rev * 10 + val;
           value = value / 10;
           }


     return(rev);


but thx anyways.
shdwcat
New User
New User
 
Posts: 27
Joined: Sun Nov 11, 2012 6:48 pm
Location: FL
Blog: View Blog (0)


Re: Need help plz

Post by WallShadow on Sun Nov 18, 2012 5:09 pm
([msg=71085]see Re: Need help plz[/msg])

Awww, and I just finished it...


Code: Select all
#include <cstdlib>
#include <iostream>

using namespace std;

int reverse(int value);


int main()
{ //Do not edit anything between this comment and the next comment.
   int value;
   cout << "Enter a positive integer less than 1000000: ";
   cin >> value;
   value = reverse(value);
   cout << "\nYour integer in reverse order is: " << value;
   cout << "\n\n\n";
   
   system("PAUSE");
   return EXIT_SUCCESS;
} // Do not edit anything between the previous comment and this one.


int reverse( int value)
    {
         int sum = 0;
         int val;
         
    /*I know 5th and 6 integers goes here but I dont know
         and cant find formula to reverse 5th and 6th any help plz*/

         
         val = value / 100000;
         sum = val;
         value = value - (val * 100000);



         val = value / 10000;
         sum += val * 10;
         value = value - (val * 10000);
         
         val = value / 1000;
         sum += val * 100;
         value = value - (val * 1000);
         
         val = value / 100;
         sum += val * 1000;
         value = value - (val * 100);

         val = value / 10;
         sum += val * 10000;
         value = value - (val * 10);
       
         sum += value * 100000;

    return(sum);
    }

User avatar
WallShadow
Contributor
Contributor
 
Posts: 612
Joined: Tue Mar 06, 2012 9:37 pm
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests