I need to write a Program for My Programming class but I am stuck

The Program is supposed to repeatedly prompt the user for the three coefficients values,a,b and c, and will then evaluate the expression below and display the two possible values for x(I used X and Y as my two values). And when a=999 it will terminate the program without asking for b or c.
These are the errors I get when I try to compile. Am I even on the right track or am I way off?

Any help would be appreciated

Error E2277 program1.cpp 18: Lvalue required in function main()
Error E2451 program1.cpp 26: Undefined symbol 'Return' in function main()
Error E2379 program1.cpp 26: Statement missing ; in function main()
Error E2134 program1.cpp 27: Compound statement missing } in function main()
*** 4 errors in Compile ***


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
 #include<iostream.h>
#include<math.h>
int main()
{
int X;
int Y;
int a;
int b;
int c;
cin>>a;
while(a!=999)
{
cin>>b;
cin>>c;
}
if (650-7*c*c<=-1)
cout<<"Negative under the radical"<<endl;
else if (a-4*c=0)
	cout<<"Divided by zero"<<endl;
else
{
X=(-3*b)-sqrt(650-7*c*c)/(a-4*c);
Y=(-3*b)-sqrt(650-7*c*c)/(a-4*c);
cout<<X<<endl;
cout<<Y<<endl;
Return 0;
}
Last edited on
Some suggestions:
- Compile your code frequently (continuously, if possible). This will help you catch syntax and logic errors as they appear, avoiding situations where you have to fix code that you don't completely remember.
- Use an editor that indents your code for you (this is basic stuff, but you're certainly working in an environment from 30 years ago). This helps track the structure of your code, and avoids most cases of mismatched braces.
- Use your tools to help you. Compile with as many warnings as your tools support, and fix them.

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
// NOTE: these headers are obsolete, common in code written before 1998.
// In modern code, the following lines would appear:
//   # include <cmath>
//   # include <iostream>
#include <math.h>
#include <iostream.h>

int main() {
  // NOTE: the user can enter real numbers, not just INTegers.  Use "double".
  double a, b, c;
  cout << "Enter three coefficients of the quadratic equation:\n";
  while (cin >> a >> b >> c) {
    // NOTE: declare variables as close as possible to where they are used.
    // For variables whose values do not need to be modified, use "const".
    // NOTE: for terms which appear multiple times, store them in a constant.
    double const radicand = 650.0 - (7.0 * c * c);
    // NOTE: there is no implicit multiplication
    double const divisor  = a - 4.0 * c;
    if (radicand < 0.0)
      cout << "Negative under the radical" << endl;
    // NOTE: comparison is ==, assignment is =.
    else if (divisor == 0.0)
      cout << "Divided by zero" << endl;
    else {
      // TODO: rename the constants as something better.
      double const minuend = (-3.0 * b);

      // NOTE: X and Y have the same value.  (Is this intended?)
      double const X = minuend - sqrt(radicand) / divisor;
      double const Y = minuend - sqrt(radicand) / divisor;

      cout << X << '\n' << Y << '\n';
    }

    cout << "Enter three more coefficients, or control-Z/control-D to quit.\n";
  }

  return 0;
}

Last edited on
Sorry I wasn't clear on some things.
1. My professor wants us to only use ints or floats in this project as that is what we have learned. So how would I write it without the const.

Here is the assignment paper he handed out. https://imgur.com/a/NnJWv

P.S.
Your notes inbetween the lines really made it easy to understand what you where saying, thanks for that.
My professor wants us to only use ints or floats in this project as that is what we have learned. So how would I write it without the const.


Change double to float
The const doesn't change what it is - it just means it's a constant.
If you must not use const too, change double const to float.
Topic archived. No new replies allowed.