assignment2

assignment2 - << endl...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* Program statement This program will solution to a quadratic formula using the user inputted coefficeints A, B and C. #include <iostream> #include <iomanip> #include <math.h> using namespace std int main() { float A, B, C, Discrim cout << scientific << setprecision(4) << endl << "This program will provide solutions for an equation of the form:" << "\n\n\t\tA*x^2 + B*x + C = 0\n\n" << "where A, B and C are integers, and A is not equal to zero.\n\n" << "Please enter the integer values for A, B and C separated by spaces: " cin >> A >> B >> C Discrim = B * B - 4 * A * C if (A == 0) cout << "\nNo solutions will be calculated for a leading coefficient of 0!"
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &lt;&lt; endl &lt;&lt; endl else if (Discrim &gt; 0) { cout &lt;&lt; &quot;\nThe two real solutions are:\t x = &quot; &lt;&lt; (-B + sqrt(B * B - 4 * A * C)) / (2 * A) &lt;&lt; &quot;\n and:\t x = &quot; &lt;&lt; (-B - sqrt(B * B - 4 * A * C)) / (2 * A) &lt;&lt; endl &lt;&lt; endl return 0 } else if (Discrim == 0) { cout &lt;&lt; &quot;\nThe one real solutions is:\t x = &quot; &lt;&lt; -B / (2 * A) &lt;&lt; endl &lt;&lt; endl return 0 } else if (Discrim &lt; 0) { cout &lt;&lt; &quot;\nThe two imaginary solutions are:\t&quot; &lt;&lt; -B / (2 * A) &lt;&lt; &quot; + &quot; &lt;&lt; (sqrt(-(B * B - 4 * A * C))) / (2 * A) &lt;&lt; &quot; * i&quot; &lt;&lt; &quot;\n and:\t&quot; &lt;&lt; -B / (2 * A) &lt;&lt; &quot; - &quot; &lt;&lt; (sqrt(-(B * B - 4 * A * C))) / (2 * A) &lt;&lt; &quot; * i&quot; &lt;&lt; endl &lt;&lt; endl return 0 } }...
View Full Document

This note was uploaded on 03/04/2008 for the course CSCI 101L taught by Professor Ghyam during the Spring '07 term at USC.

Ask a homework question - tutors are online