Answered # Need help

Featured Reply Stefano Mtangoo 441 Featured Reply Maritimo 15 Featured Reply deceptikon 1,775 Rafiii 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 ...

1

The Code below shows how to iterate Strings.

With Efforts you should be able to get what you want

God bless you!

```
#include <string>
#include <iostream>
int main()
{
int i=0;
std::string s = "UJehova uyaphile Yesu Mwema!";
for(i; i<s.length(); i++)
{
std::cout<<s[i]<<std::endl;
}
return 0;
}
```

1

Taking into account that:

```
If a number N ends in zero then the remainder of N integer divided by ten is zero
```

You could count the number of zeroes inside a number N with the following algorithm:

```
Initialize Counter to zero
While N is greather than zero
IF N ends in zero then increment Counter
Integer divide N by ten
End while
Print Counter.
```

*Edited 1 Year Ago by Maritimo*

1

You could count the number of zeroes inside a number N with the following algorithm

And if the number *begins* with zeroes? What if the number exceeds the range of your numeric type? The best approach to handle input as it's typed is to work with it as a string rather than a numeric data type, like in Stefano's hint.

*Edited 1 Year Ago by deceptikon*

0

even tho both gentleman before did provide great help i just wanted to participate since i'm still a student like you .

```
#include <iostream>
#include <string>
using namespace std;
int main()
{
string inputNum;
int numCount = 0;
cout << "Please enter an 8 digit number" << endl;
cin >> inputNum;
while ((inputNum.length() > 8) || (inputNum.length() < 0)) // make sure the range is equal or less than 8 digit & larger than 0
{
cout << "Sorry you have entered an invalide range - please re enter an 8 digit number " << endl;
cin >> inputNum;
}
for (int counter = 0; counter < inputNum.length(); counter++) // loop throughout the entire string in order to read each char
{
if (inputNum[counter] == '0' ) // if char '0' match increase the numCount for final display
{
numCount++;
}
else
{
;
}
}
cout << "There are ; " << numCount << " Zero (0) in this number " << endl;
system("pause");
return 0;
}
```

Thank You.

This question has already been answered. 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 ...