Void function (c++) -


i want create program solve quadratic equation (ax²+bx+c=0) using 2 void functions: 1 insert values of a,b,c, , second solving equation. did:

#include <iostream> #include <math.h>  using namespace std;  void add_nmbr(int a, int b, int c){      int *pa,*pb,*pc;     cout << "entrer le nombre " <<endl;     cin >> a;     cout << "entrer le nombre b " <<endl;     cin >> b;     cout << "entrer le nombre c " <<endl;     cin >> c;     pa = &a;     pb = &b;     pc = &c;     cout << <<"x2 + "<<b<<"x + "<<"c = 0"<<endl;  }  void resoudre(int a,int b, int c){      double delta;     double x1,x2;     delta= b*b-4*a*c ;      if (delta<0){         cout << "pas de solution !"<<endl;     }else{         x1=(-b-(sqrt(delta)))/(2*a);         x2=(-b+(sqrt(delta)))/(2*a);     }     cout << <<"x2 + "<<b<<"x + "<<"c = 0"<<endl;     cout << "la solution est : " << x1 << endl;     cout << "la solution est : " << x2 << endl; }  int main() {     int a,b,c;      add_nmbr(a,b,c);     resoudre(a,b,c);      return 0;  } 

when declare function void add_nmbr(int a, int b, int c) passing parameters value means pass copy of value function. can change value inside add_nmbr a value stays inside function. in case, variable a in function main stays un-initialized.

the same thing resoudre. fix it, can use reference, this

void add_nmbr(int &a, int &b, int &c) {...}     

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -