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 6627
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?
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...

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...

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...

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...

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...

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...

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...

by: CloudSolutions 
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

by: Faith0G 
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

by: Charles Arthur 
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone

by: aa123db 
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...

by: ryjfgjl 
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and timeconsuming...

by: ryjfgjl 
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...

by: emmanuelkatto 
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel

by: nemocccc 
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

by: Sonnysonu 
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by columnwise with in the specific length.
suppose the i have to...
 