root = b * b - 4.0f * a * c;
So, what I'm really looking for is some explanation as well as some help. In the above line of code, what is the purpose of using "4.0f" instead of just "4.0" or "4"?
Also, I need to write a function into the program that will check to make sure the value of "a" is not equal to zero. Specifically, if "a" is zero, the program should give the user one more try to enter the variables, and then terminate if "a = 0" a second time.
Here's what I've got for that portion:
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
int a, b, c;
cout << "Enter the values for a, b and c.";
cin >> a >> b >> c;
cout << endl;
if (a == 0)
{
cout << "The value of 'a' cannot equal zero. Please reenter a, b and c." << endl;
cin >> a >> b >> c;
}
if (a == 0)
{
cout << "The value of 'a' is still not valid. Please restart the program and try again." << endl; //If statement a<=0
}
system ("cls");
cout << a << char(253)<< " + " << b << "x + " << c << " = 0" << endl;
system ("pause");
return 0;
A bit sloppy maybe? What do I need to do to get the program to terminate after the second if statement if "a" is still equal to zero?
Thanks in advance for taking the time to read all this.

New Topic/Question
Reply



MultiQuote





|