Need help with first assignment beginner

-
Last edited on
you seem to confond assignment and comparison in your for loop .

Also result cannot evaluate -4 val , it must be -4 * val , etc.
-
Last edited on
closed account (E0p9LyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include<cmath>

int main ()
{
   double val = 0;
   double result = 0;

   for (val =- 3; val <= 5; val+=0.5)
   {
      // this is complete gibberish, what are you trying to do?
      /* result=(-4 val*-4 val*-4 val-3 val*3 val-15 val+22) /
             abs (2- val*2- val*2- val*2 val)+sqrt(2 val*2 val+8); */

      std::cout << val << "\t" << result << "\n";
   }

   return 0;
}


-3      0
-2.5    0
-2      0
-1.5    0
-1      0
-0.5    0
0       0
0.5     0
1       0
1.5     0
2       0
2.5     0
3       0
3.5     0
4       0
4.5     0
5       0
-
Last edited on
closed account (E0p9LyTq)
The formula as written is gibberish. The following is my interpretation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include<cmath>

int main ()
{
   double dividend = 0;
   double divisor = 0;
   double result = 0;

   for (double val =- 3; val <= 5; val += 0.5)
   {
      // I split the equation into parts for easier analysis
      dividend = -4 * (val * val * val);
      dividend += 8 * (val * val);
      dividend -= 9 * val;
      dividend += 18;

      divisor = abs((7 - (val * val * val)));
      divisor += sqrt(3) * (val * val);
      divisor += 10;

      result = dividend / divisor;

      std::cout << val << "\t" << result;

      if (result == 0)
      {
         std::cout << "\t\tzero\n";
      }
      else
      {
         if (result < 0)
         {
            std::cout << "   \tnegative\n";
         }
         else
         {
            std::cout << "   \tpositive\n";
         }
      }
   }

   return 0;
}

-3      3.7759          positive
-2.5    3.57265         positive
-2      3.13203         positive
-1.5    2.6363          positive
-1      1.97648         positive
-0.5    1.43406         positive
0       1.05882         positive
0.5     0.912797        positive
1       0.733136        positive
1.5     0.532635        positive
2       0               zero
2.5     -0.589759       negative
3       -0.987092       negative
3.5     -1.31385        negative
4       -1.5415         negative
4.5     -1.74319        negative
5       -1.90892        negative
i really appreciate it but in my college we never learned dividend or divisor if i submit this i will get a zero in class because my professor would know i got help. i think i know what to do now but one last thing furry guy can you write me the formula without splitting the equation into smaller parts and not including dividenend and divisor cause we havent learned that yet. i tried writing the equation like this is it correct?

(-4*val-4*val-4*val+8*val+8*val-9*val+18)/
abs (7-val*7-val*7-val)+sqrt(3*val*3*val+10);
closed account (E0p9LyTq)
1
2
result = ((-4.0 * pow(val, 3.0)) + (8.0 * pow(val, 2.0) - (9.0 * val) + 18.0)) /
         (abs(7.0 - pow(val, 3.0)) + (sqrt(3.0) * pow(val, 2.0) + 10.0));
Last edited on
thank you so much Furry guy now how do i put it all together to print out this output you gave me.
-3 3.7759 positive
-2.5 3.57265 positive
-2 3.13203 positive
-1.5 2.6363 positive
-1 1.97648 positive
-0.5 1.43406 positive
0 1.05882 positive
0.5 0.912797 positive
1 0.733136 positive
1.5 0.532635 positive
2 0 zero
2.5 -0.589759 negative
3 -0.987092 negative
3.5 -1.31385 negative
4 -1.5415 negative
4.5 -1.74319 negative
5 -1.90892 negative


This is what i have so far

//this is the output of my first program
#include <iostream>
#include<cmath>
using namespace std;
int main ()
Last edited on
closed account (E0p9LyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cmath>

int main ()
{
   for (double val =- 3.0; val <= 5.0; val += 0.5)
   {
      double result = ((-4.0 * pow(val, 3.0)) + (8.0 * pow(val, 2.0) - (9.0 * val) + 18.0)) /
                      (abs(7.0 - pow(val, 3.0)) + (sqrt(3.0) * pow(val, 2.0) + 10.0));

      std::cout << val << "\t" << result;

      if (result == 0.0)
      {
         std::cout << "\t\tzero\n";
      }
      else
      {
         if (result < 0.0)
         {
            std::cout << "   \tnegative\n";
         }
         else
         {
            std::cout << "   \tpositive\n";
         }
      }
   }

   return 0;
}
Topic archived. No new replies allowed.