Octal to Decimal number conversion program

Reply

Join Date: Feb 2008
Posts: 8
Reputation: newport is an unknown quantity at this point 
Solved Threads: 0
newport newport is offline Offline
Newbie Poster

Octal to Decimal number conversion program

 
0
  #1
Feb 13th, 2008
I'm trying to make a program that converts octal numbers to decimal numbers. I know the concept is taking the %10 of the number to get the first digit, /10 the number then take the %10 to get the second digit and multiplying by increase powers of 8, but I have no idea how to translate this to a program. Could someone please guide me in the right direction.

  1. #include <stdio.h>
  2.  
  3. int main ()
  4.  
  5. {
  6.  
  7. int num1, base8, x, y, n, lastDigit;
  8.  
  9. printf("Enter an integer in base 8: ");
  10. scanf("%d", &num1);
  11.  
  12. num1 %10 =lastDigit;
  13.  
  14. n = 1;
  15. x=num1
  16.  
  17. if(num1 > 10){
  18. x/10 = x;
  19. x %10 =y;
  20.  
  21. while (x != y) {
  22.  
  23. x/10 = x;
  24. x %10 =y;
  25. base8 = y*8^n
  26. n = n + 1;
  27. }}
  28. sum= base8+lastDigit;
  29. printf("%d", sum);
  30.  
  31. return 0;
  32.  
  33. }
Last edited by newport; Feb 13th, 2008 at 2:19 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Octal to Decimal number conversion program

 
0
  #2
Feb 13th, 2008
It would help if you'd format your code so we can follow it's flow. Proper indentation is crucial to understanding.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,660
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 723
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Octal to Decimal number conversion program

 
0
  #3
Feb 13th, 2008
>I'm trying to make a program that converts octal numbers to decimal numbers.
I don't suppose this would work for you:
  1. #include <stdio.h>
  2.  
  3. int main ( void )
  4. {
  5. int number;
  6.  
  7. scanf ( "%o", &number );
  8. printf ( "%d\n", number );
  9.  
  10. return 0;
  11. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 8
Reputation: newport is an unknown quantity at this point 
Solved Threads: 0
newport newport is offline Offline
Newbie Poster

Re: Octal to Decimal number conversion program

 
0
  #4
Feb 13th, 2008
it does works, but i believe i am suppose to come up with a formula. thanks.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Octal to Decimal number conversion program

 
0
  #5
Feb 13th, 2008
Firstly, base8 = y*8^n does not have semi-colon at the end of the statement. Secondly, ^ is not a power operator. I think you are confusing with Visual Basic. Moreover, x/10 = x; and x %10 =y; are not right. It should be x = x / 10 .
Last edited by invisal; Feb 13th, 2008 at 1:23 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,660
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 723
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Octal to Decimal number conversion program

 
0
  #6
Feb 13th, 2008
>i believe i am suppose to come up with a formula
I figured, but it was worth a shot. My advice is to figure out the exact steps you use to do this conversion on paper. It's hard to tell the computer how to do something if you can't lay out the steps one by one.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC