Question: What is wrong with my code?? #include std::string seriesSum(int n) { double sum = 0.; std::string totalSum; if (n == 0) return 0.00; for(int i
What is wrong with my code??
#include
std::string seriesSum(int n) { double sum = 0.; std::string totalSum; if (n == 0) return "0.00"; for(int i = 1; i I don't know why its not working. Can someone please explain? I'm practicing coding problems and really want to become a better coder. I will give a thumbs up for great explanations.
The instructions are:


Time: 1549ms Errors: 1 Exit Code: 1 | SIDERR: main.cpp:16:9: error: assigning to 'double' from incompatible type '_Complex double' += 1.0/(31-2); sum A 1 error generated. Instructions Output Task: Your task is to write a function which returns the sum of following series upto nth term(parameter). Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +... Rules: You need to round the answer to 2 decimal places and return it as String. If the given value is 0 then it should return 0.00 You will only be given Natural Numbers as arguments. Examples: SeriesSum(1) => 1 = "1.00" SeriesSum(2) => 1 + 1/4 "1.25" SeriesSum(5) => 1 + 1/4 + 1/7 + 1/10 + 1/13 = "1.57" NOTE: In PHP the function is called series_sum(). FUNDAMENTALS LOOPS CONTROL FLOW BASIC LANGUAGE FEATURES ARITHMETIC MATHEMATICS ALGORITHMS NUMBERS SEQUENCES ARRAYS powered by Qualified
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
