I am new to this forum and C++ (I'm struggling to understand functions). I decided to make a program to help solve a quadratic formula to try to get the gist of functions, and I saw several examples online...They did not help very much though because I did not understand much of them. So here is my code:
#include <iostream>
#include <cmath>
using namespace std;
int quadraticform (int a, int b, int c)
{
int r;
r=(-b+(sqrt(b*b))-(4*a*c)))/(2*a);
return (r);
}
int main()
{
cout<<"Enter value a: ";
cin>>a;
cout<<"Enter value b: ";
cin>>b;
cout<<"Enter value c: ";
cin>>c;
cin.ignore();
cout << "The result is " << quadraticform (a, b, c) << "\n";
cin.get();
}
I know it probably is all discombobulated and it may not make sense, so I'll explain what it's supposed to do. You enter the three variables (a, b, c), and it sends them to quadraticform to do the equation. Then, it's supposed to display the result (if it is a real number)...It sounded simple enough when I started, but not anymore... I would also like to have some decimals on my answer too, although I'm not sure how to do that. Sorry this is quite long, but I tried all sorts of things already. Thanks in advance.
The errors apparently are:
a, b, c were not displayed in this scope //at cin>>a, cin>>b, and cin>>c
I changed it, and it handles solutions with whole numbers only (no imaginary or even irrational ones yet), and it only shows the positive solution but that's all I really expect right now. Thanks a lot! Replies come fast in this forum. (It was probably too easy haha).