Hi guys.
I'm taking my first CS course this fall.
Pretty neat stuff.
So we have this assignment due in a couple days.
I have it working and everything; I'm just not getting the right values.
So this is the prompt:
"Design a C++ program that will:
Use Cramer's Rule to solve for x and y. (Remember that x and y may not turn out to be whole numbers, so declare them of an appropriate data type.)
Display the original equations (see sample output below).
Display the computed values of x and y with labels. Do NOT set precision for these values."
Here is my source code:
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 45 46 47 48 49 50 51
|
#include <iostream>
using namespace std;
int main ()
{
int a; // Declaring the value of a as an integer.
int b;
int c;
int d;
int e;
int f;
float x; // Declaing the value of x as more than just an integer.
float y;
cout << " " << endl;
cout << "My Name" << endl;
cout << "CS 135 Section 1003" << endl;
cout << "Assignment 03" << endl;
cout <<" " << endl;
cout <<"This program will solve for x and y using Cramer's Rule." << endl;
cout << "The following two equations shall be used: \n ax + by = c \n dx +ey = f \n \n";
cout << "Enter the integer value for a" << endl;
cin >> a;
cout << "Enter the integer value for b" << endl;
cin >> b;
cout << "Enter the integer value for c" << endl;
cin >> c;
cout << "Enter the integer value for d" << endl;
cin >> d;
cout << "Enter the integer value for e" << endl;
cin >> e;
cout << "Enter the integer value for f" << endl;
cin >> f;
cout << "" << endl;
cout << "Your first equation is: " << a << "x +" << b << "y = " << c << endl;
cout << "Your second equation is: " << d << "x +" << e << "y = " << e << endl;
cout << "" << endl;
x= ((c * e) - (b * f))/((a * e) - (b * d));
y= ((f * a) - (c * d))/((a * e) - (b * d));
cout << "x=" << x << endl;
cout << "y=" << y << endl;
cout << "" << endl;
return 0;
}
|
The values that I get for x and y are incorrect.
I know that there's a problem with int or float or something akin to that.
Any help would be greatly appreciated.