Not Yet Answered # help me in my code

joshmo 8 Discussion Starter Lotus_2011 Narue 5,707 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

you are not explaining your problem clearly...from what you said you want to convert a number input from decimal to octal. from your code, you are finding the remainder then you output it and then you are calculating value...is this the whole code or part of it???why dont you elaborate on the question and your problem a little more

0

Look my code here isn't complete.As output must be 32 if input is 26

The output in my code 23

I just wnt to inverse it

Do you understand me?

0

When you make a conversion like that, you get the digits in reverse. There are a number of ways to swap the order. First you have recursion:

```
#include <iostream>
#include <ostream>
void to_octal ( std::ostream& out, int value, int n = 0 )
{
if ( value == 0 ) {
if ( n == 0 )
out<< value;
return;
}
to_octal ( out, value / 8, n + 1 );
out<< value % 8;
}
int main()
{
to_octal ( std::cout, 26 );
std::cout<<'\n';
}
```

Another is converting each digit to a character and storing them in a string. You can either push them to the front of the string if that's a supported operation, or reverse the string at the end:

```
#include <iostream>
#include <string>
std::string to_octal ( int value )
{
if ( value == 0 )
return "0";
std::string result;
while ( value != 0 ) {
char digit = value % 8 + '0';
result = digit + result;
value /= 8;
}
return result;
}
int main()
{
std::cout<< to_octal ( 26 ) <<'\n';
}
```

```
#include <algorithm>
#include <iostream>
#include <string>
std::string to_octal ( int value )
{
if ( value == 0 )
return "0";
std::string result;
while ( value != 0 ) {
char digit = value % 8 + '0';
result += digit;
value /= 8;
}
std::reverse ( result.begin(), result.end() );
return result;
}
int main()
{
std::cout<< to_octal ( 26 ) <<'\n';
}
```

Or if you don't want to do a character conversion for some reason, you can store the digits on a stack. When they get popped off, everything will be in the right order:

```
#include <iostream>
#include <ostream>
#include <stack>
void to_octal ( std::ostream& out, int value )
{
if ( value == 0 )
out<< value;
else {
std::stack<int> save;
while ( value != 0 ) {
save.push ( value % 8 );
value /= 8;
}
while ( !save.empty() ) {
out<< save.top();
save.pop();
}
}
}
int main()
{
to_octal ( std::cout, 26 );
std::cout<<'\n';
}
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...