473,568 Members | 2,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linear equation code problem

5 New Member
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.



Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. void displayMessage(); 
  4.  
  5. int hasSolution(double a, double b, double d, double e);
  6.  
  7. double getX(double a, double b, double c, double d, double e, double f); 
  8.  
  9. double getY(double a, double b, double c, double d, double e, double f);
  10.  
  11. void displaySolutions(double x, double y); 
  12.  
  13.  
  14. int menu(); 
  15.  
  16.  
  17. int main() {
  18.     double a, b, c, d, e, f;    
  19.     double x, y;                
  20.     int choice;               
  21.     displayMessage();
  22.  
  23. do
  24.     {
  25.         do
  26.         {
  27.          menu();
  28.          scanf( "%d", &choice );
  29.         } while (choice < 1 || choice > 3); 
  30.         switch (choice) 
  31.  
  32.         {
  33.  
  34.             case 1:    
  35.                 printf(  "Enter a, b, and c: " );
  36.                 scanf( "%lf", &a );
  37.                 scanf( "%lf", &b );
  38.                 scanf( "%lf", &c );
  39.                 printf(  "Enter d, e, and f: " ); 
  40.                 scanf( "%lf", &d );
  41.                 scanf( "%lf", &e );
  42.                 scanf( "%lf", &f );
  43.                 break;
  44.            case 2:    
  45.                 if (hasSolution(a, b, d, e))
  46.                 {   
  47.                     x = getX(a, b, c, d, e, f);
  48.                     y = getY(a, b, c, d, e, f);
  49.                     displaySolutions(x,y);
  50.                 }                
  51.                     else
  52.                     {    
  53.                         printf( "The system has no solution\n" );
  54.  
  55.                     }
  56.                break; 
  57.            case 3:     
  58.                printf(  "Thanks for using my program\n" ); 
  59.         } 
  60.     } while (choice != 3);    
  61.  
  62.  
  63.     return 0;
  64. }
  65.  
  66.  
  67.  
  68. void displayMessage(){
  69.        printf( "This program calculates solutions to systems of linear equations of the form\n\n");
  70.        printf( "     aX + bY = c\n" );
  71.        printf( "     dX + eY = f\n\n" );
  72.        return;
  73. }
  74.  
  75. int hasSolution(double a, double b, double d, double e){
  76.         int s;
  77.         s=(a*e - d*b != 0);
  78.         return s;
  79. }
  80.  
  81.  
  82. double getX(double a, double b, double c, double d, double e, double f){
  83.         double x;
  84.         x=(c * e - f * b) / (a * e - d * b); 
  85.         return x;
  86. }
  87.  
  88.  
  89. double getY(double a, double b, double c, double d, double e, double f){
  90.         double  y;
  91.         y=(a * f - d * c) / (a * e - d * b);
  92.         return y; 
  93. }
  94.  
  95.  
  96. void displaySolutions(double x, double y)
  97. {
  98. printf ("The solution is (%lf, %lf)\n", x, y ); 
  99. return;
  100. }
  101.  
  102. int menu()
  103. {
  104.             printf( "\nEnter  1 to enter a new system\n" );
  105.             printf( "       2 to find the solution of the system\n" );
  106.             printf( "       3 to exit\n" );
  107.             printf( "Choice: " );
  108. return 0;
  109. }
Nov 14 '07 #1
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?
Nov 15 '07 #2
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().
Nov 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4245
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
2
1430
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, ...)....
3
11030
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
13
3212
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...
1
4788
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
4
9344
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
7
5778
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!
7
4096
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 {...
10
2355
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...
0
7693
marktang
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...
0
7604
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...
0
8117
jinu1996
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...
0
7962
tracyyun
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...
0
5217
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.