Keep the rhythm with the count
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
|
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int X = 0;
double a, b, c, xMin, xMax;
double y = 0;
cout << "#1(A): ";
cin >> a;
cout << "\n#2(B): ";
cin >> b;
cout << "\#3(C): ";
cin >> c;
cout << "Enter Xmin" << endl;
cin >> xMin;
cout << "Enter Xmax" << endl;
cin >> xMax;
y = a + b + c + X;
for (int count = xMin; count <= xMax; count++)
{
cout << count << "\t" << y << "\n";
}
return 0;
}
|
The program is meant to perform the quadratic formula, everything is fine till I tried to get this output from the bottom section of the code
a+b+c = 3
xMin = 2, xMax = 6
Output
2----5
3----6
4----7
5----8
6----9
Instead
it's just
2---0
3----0
4 ---0
5----0
6----0
For something to that affect
Adding a link to xMin and xMAx doesn't seem to help either.
I'm not sure on how to proceed to achieving this result.
Last edited on
Did you mean
1 2 3 4
|
for (X= xMin; X<= xMax; X++)
{
cout << X << "\t" << y+X<< "\n";
}
|
?
Sorry, but I don't understand your program at all -..-
Maybe cause of my math s**ks...
Last edited on
line 32; y = a + b + c + X;
should be moved inside the loop, so that it is executed each time.
Also the quadratic formula looks more like:
ax2 + bx + c
rather than
a + b + c + x
I see what's it.
And refer to what
Chervil said,
Maybe you should use,
1 2 3 4
|
for (X= xMin; X<= xMax; X++)
{
cout << X << "\t" << (a*X*X+b*X+c) << "\n";
}
|
Last edited on
Thank you lsk & Chervil.
That did the trick, gotta love the little nuances in coding.
Cheers
Topic archived. No new replies allowed.