+ 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.
4th Jun 2022, 7:59 AM
XXX
XXX - avatar
+ 4
I changed this for(int i=1;i<length;i++) { Product=Product*str[i]-'0'; } And received a positive value...
4th Jun 2022, 8:01 AM
Ausgrindtube
Ausgrindtube - avatar
+ 3
a*b-c is different than a*(b-c) according to precedence rules...
4th Jun 2022, 9:01 AM
Jayakrishna 🇼🇳
+ 2
// Or #include <stdlib.h> /* atoi */ string str="123"; int p = 1; for(auto s : str) p *= atoi(&s); cout << p << endl;
4th Jun 2022, 1:11 PM
SoloProg
SoloProg - avatar
+ 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]).
6th Jun 2022, 7:46 AM
Ausgrindtube
Ausgrindtube - avatar
- 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.
6th Jun 2022, 6:34 AM
Jonathan Trapella