+ 4
When i = 2, you are doing
Product * str[i + 1] - '0'
=> Product * str[3] - '0'
=> Product * 0 - '0'
=> 0 - 48
=> -48
There are 2 bugs hidden in the problem I showed you, try to find them yourselves. If you can't figure them out, I'll help.
+ 4
I changed this
for(int i=1;i<length;i++)
{
Product=Product*str[i]-'0';
}
And received a positive value...
+ 3
a*b-c is different than a*(b-c) according to precedence rules...
+ 2
// Or
#include <stdlib.h> /* atoi */
string str="123";
int p = 1;
for(auto s : str) p *= atoi(&s);
cout << p << endl;
+ 2
vox voxx you should reread the lesson and then search the forum for the answer first. If you still have a problem, post your own question, don't take over another person's thread (many people won't read it, especially after it has [solved]).
- 3
hello there
what's the solution of the 27.7 practise exercise of the python beginner course?
------------------------------------------------
Prob:
Write a program that takes an input string and outputs the 3rd character of the string.
this does work only for case 1 and not case 2:
a = str("hello")
print(a[2])
Viceversa then it works for case 2 and not 1.
AND PUTTING THEM TOGETHER RESULTS IN AN ERROR.
------------------------------------------------
Any ideas?
thank you very much indeed.