Thread: Help with my program's logic?

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Help with my program's logic?

    Can anyone help me figure out what's wrong?I can't get the program to compile. I'm using QT and you can just ignore the QT statements (cin, cout).

    Code:
    #include <QtCore/QCoreApplication>
    #include <cmath>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
    
    int quit;
    int continueflag;
    double aa, bb, cc;
    double delta;
    double x1, x2;
    
    
    
    
    cout << "Solving quadratic equation" << endl;
    
    while (!quit) {
    	cout << "What is the value of a? " << endl;
    	cin >> aa;
    	cout << "What is the value of b? " << endl;
    	cin >> bb;
    	cout << "What is the value of c? " << endl;
    	cin >> cc;
    
    	delta = bb * bb - 4.0 * aa * cc;
    	if ((delta >= 0) && (aa != 0.0)) {
    		x1 = (-bb + sqrt(delta)/(2.0 * aa);
    		x2 = (-bb - sqrt(delta)/(2.0 * aa);
    
    		cout << "Equation solution: x1 = " << x1 << " x2 = " << x2 << endl;
    
    	}
    	else 
    		cout << "Equation is unsolvable." << endl;
    
    		
    
    	cout << "[ENTER] to try again, [Q] to quit." << endl;
    	cin >> continueflag ;
    	if (continueflag == "Q") quit = 1;
    
        return a.exec();
    	}
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's C++. This is the C forum.

    If you can't get it to compile, try compiling with your warning level turned up, then start at the top and fix the errors and warnings one by one until you don't have any left.

    Your indentation is terrible. Also, your loop has return inside of it, so it's just going to end the program on the first pass through the loop.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  2. Kind of logic problem,could use some help :)
    By yrostran in forum C Programming
    Replies: 11
    Last Post: 09-11-2006, 06:48 PM
  3. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  4. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 08:10 PM