This program calculates the solution (x,y) of a system of linear equations in 2 variables. This is my third C programming assignment so be gentle. problem: 1)on my int menu() function definition, how would I include the scanf( "%d", &choice ); in the function definition for it to run right. It runs right without it, but I need it in there. - #include <stdio.h>
-
-
void displayMessage();
-
-
int hasSolution(double a, double b, double d, double e);
-
-
double getX(double a, double b, double c, double d, double e, double f);
-
-
double getY(double a, double b, double c, double d, double e, double f);
-
-
void displaySolutions(double x, double y);
-
-
-
int menu();
-
-
-
int main() {
-
double a, b, c, d, e, f;
-
double x, y;
-
int choice;
-
displayMessage();
-
-
do
-
{
-
do
-
{
-
menu();
-
scanf( "%d", &choice );
-
} while (choice < 1 || choice > 3);
-
switch (choice)
-
-
{
-
-
case 1:
-
printf( "Enter a, b, and c: " );
-
scanf( "%lf", &a );
-
scanf( "%lf", &b );
-
scanf( "%lf", &c );
-
printf( "Enter d, e, and f: " );
-
scanf( "%lf", &d );
-
scanf( "%lf", &e );
-
scanf( "%lf", &f );
-
break;
-
case 2:
-
if (hasSolution(a, b, d, e))
-
{
-
x = getX(a, b, c, d, e, f);
-
y = getY(a, b, c, d, e, f);
-
displaySolutions(x,y);
-
}
-
else
-
{
-
printf( "The system has no solution\n" );
-
-
}
-
break;
-
case 3:
-
printf( "Thanks for using my program\n" );
-
}
-
} while (choice != 3);
-
-
-
return 0;
-
}
-
-
-
-
void displayMessage(){
-
printf( "This program calculates solutions to systems of linear equations of the form\n\n");
-
printf( " aX + bY = c\n" );
-
printf( " dX + eY = f\n\n" );
-
return;
-
}
-
-
int hasSolution(double a, double b, double d, double e){
-
int s;
-
s=(a*e - d*b != 0);
-
return s;
-
}
-
-
-
double getX(double a, double b, double c, double d, double e, double f){
-
double x;
-
x=(c * e - f * b) / (a * e - d * b);
-
return x;
-
}
-
-
-
double getY(double a, double b, double c, double d, double e, double f){
-
double y;
-
y=(a * f - d * c) / (a * e - d * b);
-
return y;
-
}
-
-
-
void displaySolutions(double x, double y)
-
{
-
printf ("The solution is (%lf, %lf)\n", x, y );
-
return;
-
}
-
-
int menu()
-
{
-
printf( "\nEnter 1 to enter a new system\n" );
-
printf( " 2 to find the solution of the system\n" );
-
printf( " 3 to exit\n" );
-
printf( "Choice: " );
-
return 0;
-
}
2 6643 sicarie 4,677
Recognized Expert Moderator Specialist
You would put that into your menu. I'm not sure what you are confused on - your code looks right, you seem to know what you need, you just have to move the code in there, and then make sure it returns properly. Could you say what you're stuck on?
Ganon11 3,652
Recognized Expert Specialist
Basically, you would make your menu function return the scanf'd variable. Put int choice inside the menu function, set it to the scanf statement, and return choice. Back in main(), keep int choice, but instead of scanf'ing it, initialize it with the return value of menu().
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Guenther Sohler |
last post by:
I am looking for a apropriate c library to solve my
sparse linear equation system.
I have n variables and m equations.
m might be less, equal or greater then n!!!!
If there are less equations than variables, the system should
effectively set undefined variables to 0
|
by: Anatoly |
last post by:
Hi All !!!
Can anyone give me link to the C++ source or to the compiled program unit
(compatible with Microsoft VC++), designed for the solving of the algebraic
linear systems with rare matrices ? The main problem is next: the main rare
matrix of the system is in the common form, but not in the special (non
triangular, non symmetric, ...)....
|
by: sql guy123 |
last post by:
This is a real challenge. I hope someone is smart enough to know how
to do this.
I have a table
TABLE1
|
by: RS |
last post by:
Hi all,
I am looking for a fast, efficient (tuned for speed, not size) and
mature C++ code to do some numerical work with. I have looked at the
Template Numerical Toolkit, which the oonumerics.org web page claims is
a successor to lapack++. But on the surface it doesn't seem to have all
the functionalities of lapack++, let alone being its...
|
by: wirecom |
last post by:
Hi all,
I am seeking a module that will do the equivalent of linear regression in
3D to yield a best fit a plane through a set of points (X1, Y1, Z1), (X1,
Y1, Z1),... (Xn, Yn, Zn).
The resulting equation to be of the form:
Z = aX + bY + c
| |
by: Thomas |
last post by:
Hi,
I've to solve a system of linear equations and inequations in C++. Are
there (free) librarys for that topic?
Regards,
Thomas
|
by: spranto |
last post by:
Hi to you all,
This is my first post. I'm having troubles finding one suitable code line to solve a 3 non linear equation system. I'm here asking if someone allready done that and if it possible to share that with me, if not if someone can point me in the wright direction to achieve this goal.
Thank's in advance!
|
by: Bigs |
last post by:
Ok, I have been working on a Linear Equation program that will draw a line on my graph. But, I am not sure how to set up the y=mx+b in Java to return the (x1,y1) and (x2, y2) using only the slope and y-intercept.
Can anyone tell me how to set up the linear equation in java.
if (Global.psize == 1)//Check If Line Should Be Graphed
{...
|
by: Constantine AI |
last post by:
Hi i am having a little problem with an equation function that was created from all your help previously. The function works fine itself but with a small glitch within it.
Here is the function code.
Public Function fCalcEquation(strEquation As String) As Long
Dim MyDB As DAO.Database
Dim rstParameters As DAO.Recordset
Dim...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |