Code coach , balacon | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code coach , balacon

At this code Why num doesnt take all the input values within the loop ?. https://code.sololearn.com/cPDWn3Y2NU9Y/?ref=app

23rd Dec 2022, 10:56 PM
Shimaa
Shimaa - avatar
7 Answers
+ 2
Why are you reading integers where the task says input are two comma separated string? Neither <parta> nor <partb> were initialized, they might contain garbage values You SHOULD NOT print anything except for what the task had asked you to. I see you print values of <num> and <i> inside the loop (line 27)
24th Dec 2022, 3:00 AM
Ipang
+ 2
Dark the input formats are different between the two problems. Try something like scanf("%f,%f", ...).
25th Dec 2022, 7:13 PM
Brian
Brian - avatar
+ 2
Dark the first parameter in scanf is called the format specifier. It serves as a sort hint of the format that scanf should find on the input line. In this case, it is two floating point numbers with a comma between. (I believe "%f,%f" would work even if the input had extra spaces in the middle). It is not as smart as a Regular Expressions interpreter, so sometimes you have to take an input string and parse it in your own code. You can search the web for scanf format specifiers to see some of the details.
25th Dec 2022, 9:28 PM
Brian
Brian - avatar
23rd Dec 2022, 11:21 PM
Shimaa
Shimaa - avatar
0
Ipang I print them to see what input the code takes Not the final code Also I tried to take strings as input and turn it to integers to compare them and failed , so tried to take it like that
25th Dec 2022, 8:10 PM
Shimaa
Shimaa - avatar
0
Brian I didnt know that i can put "," on scanf to ignore it I tried hard to take the input without ',' Tried excluded the input itself And also tried to store it as an element in array and then exclude it But didnt know that scanf itself can do this 😐 And the code Workd ! Would u please explain it how ?
25th Dec 2022, 8:23 PM
Shimaa
Shimaa - avatar
0
Dark "I print them to see what input the code takes Not the final code" Actually coach judges don't care about that, you fail if your code outputs anything out of the requirement. "Also I tried to take strings as input and turn it to integers to compare them and failed, so tried to take it like that" I see, however as per the coach statement, two inputs will be fed in for the code, not four.
26th Dec 2022, 6:59 AM
Ipang