Issue with converting from octal to decimal

Hey, I'm trying to write a program that converts a number from octal to decimal, but it's not working out for me.
Here's what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
# include <math.h>
using namespace std;
void main()
{
	int num, x, count=1, res, sum=1, i, y;
	cout << "Please enter a number:" << endl;
	cin >> num;
	x=num;
         while (x>=10)
	{
		x=x/10;
		count++;
	}
	y=num;
	for (i=0; i<=count-1; i++)
	{
		res=pow(8, (double)i);
		res=res*y%10;
		sum=sum+res;
		y=y/10;
	}
	cout << sum;
}


But whenever I enter a number it just returns the number of digits. What's wrong here?

Line 19 res=res*y%10;
This is evaluated from left to right, like this: (res*y) %10;

change it to:
 
    res=res*(y%10);

or my preferred style:
 
    res *=  y%10;


Wow thanks so much, didn't notice lol.
Topic archived. No new replies allowed.