quadratic equation cpp program problems

This is a discussion on quadratic equation cpp program problems within the C++ Programming forums, part of the General Programming Boards category; this is the code i have written so far (BTW GetInteger is a short cut to just get an int ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    7

    quadratic equation cpp program problems

    this is the code i have written so far (BTW GetInteger is a short cut to just get an int straight from code)

    Code:
    #include <stdio.h>
    #include "math.h"
    
    int main() {
    	double a, b, c, ansr1, ansr2, bottomofquad;
    	int inta, intb, intc;
    	printf("Enter A: ");
    	inta = GetInteger();
    	printf("Enter B: ");
    	intb = GetInteger();
    	printf("Enter B: ");
    	intc = GetInteger();
    	a = (double)inta;
    	b = (double)intb;
    	c = (double)intc;
    	
    	bottomofquad = 2.0 * a;
    	double root = b * b + 4.0*a*c;
    	root = sqrt(root);
    	ansr1 = -b + root;
    	ansr2 = -b - root;
    	ansr1 = ansr1/bottomofquad;
    	ansr2 = ansr2/bottomofquad;
    
    	printf("The answers are %g and %g",ansr1, ansr2);
    i tested it with 3,5,2and the out put should be -0.666666666666 and -1
    but the program gives me:
    0.333333333333 and -2

    i cannot find what is the problem any help would be greatly appreciated

    cheers

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    I thought it was -4ac
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    7
    wow, simple mistakes mess everything up. than kyou

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 05-30-2007, 06:47 PM
  2. having problems with my card program
    By mac025 in forum C Programming
    Replies: 4
    Last Post: 01-31-2006, 04:26 PM
  3. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 12:53 PM
  4. Problems with Getch() program execution order
    By napkin111 in forum C++ Programming
    Replies: 4
    Last Post: 05-08-2002, 02:44 PM
  5. Quadratic Equation Program
    By Ambizzy in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 09:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21