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.
[CODE=c]#include <stdio.h>
void displayMessage( );
int hasSolution(dou ble 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 displaySolution s(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);
displaySolution s(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(dou ble 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 displaySolution s(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;
}[/CODE]
scanf( "%d", &choice ); in the function definition for it to run right. It runs right without it, but I need it in there.
[CODE=c]#include <stdio.h>
void displayMessage( );
int hasSolution(dou ble 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 displaySolution s(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);
displaySolution s(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(dou ble 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 displaySolution s(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;
}[/CODE]
Comment