What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Squadratic formula in c++

Squadratic formula in c++
Author: Message:
somelauw
Junior Member
**

Avatar

Posts: 93
34 / Male / –
Joined: Jan 2006
O.P. Squadratic formula in c++
I am a beginner c++ programmer and this is my first program.
I enter:
quote:
a=5
b=10
c=5
but it shows
discriminant=-6,9e-018
I thought 10*10-4*5*5=0?

Here my code:
code:
#include <math.h>
#include <stdio.h>

int wortelformule()
{
   float a,b,c,d,x1,x2;
   printf("ax˛+bx+c=0 \n");
   printf("The value of a is ");
   scanf("%g",&a);
   printf("The value of b is ");
   scanf("%g",&b);
   printf("The value of c is ");
   scanf("%g",&c);
   d=pow(b,2)-4*a*c;
   printf("\n \nThe discriminant is %g \n",d);
   x1=(-b+pow(d,0.5))/(2*a);
   x2=(-b-pow(d,0.5))/(2*a);
   printf("The first answer is %g \n",x1);
   printf("The second answer is %g \n \n",x2);
   wortelformule();
}

main()
{
      wortelformule();
}

Please add one 6 to my postcount and I'm tha Beast!
This signature was written when my postcount was 66
08-18-2006 04:04 PM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: Squadratic formula in c++
Using your code, cut-n-pasted:
quote:
~ $ nano -w wf.c
~ $ gcc -o wf -lm wf.c
~ $ ./wf
ax˛+bx+c=0
The value of a is 5
The value of b is 10
The value of c is 5


The discriminant is 0
The first answer is -1
The second answer is -1
Looks good to me.  Your code is fine.  I doubt there could be a problem with your input, given that typing 5, 10, 5 is easy enough.  That leaves a problem with your compiler.

So, what platform and compiler are you using?

This post was edited on 08-19-2006 at 02:18 AM by Adeptus.
08-19-2006 02:17 AM
Profile E-Mail PM Find Quote Report
somelauw
Junior Member
**

Avatar

Posts: 93
34 / Male / –
Joined: Jan 2006
O.P. RE: Squadratic formula in c++
I use "windows XP home edition"(no service pack) as platform and the program I use is "Dev-C++"

Also a minor problem the ˛ isn't shown correctly. Is there a way too show that 2 in superscript.

.png File Attachment: Wortelformule.png (13 KB)
This file has been downloaded 119 time(s).

This post was edited on 08-19-2006 at 11:10 AM by somelauw.
Please add one 6 to my postcount and I'm tha Beast!
This signature was written when my postcount was 66
08-19-2006 10:59 AM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: Squadratic formula in c++
I don't know why you are getting incorrect results.  The reason I compiled your code was because I looked it over and couldn't find any problems -- and it works fine here, as expected.

I might download Dev-C++ and see if I can duplicate your problem later this evening.

As for your other question, try:

printf("ax\375+bx+c=0 \n");

375 is the octal value for the ˛ character in the PC OEM character set used by Windows console.
08-19-2006 03:03 PM
Profile E-Mail PM Find Quote Report
somelauw
Junior Member
**

Avatar

Posts: 93
34 / Male / –
Joined: Jan 2006
O.P. RE: Squadratic formula in c++
Thank you for your efforts. Maybe there is a compiler bug.
It's obvious you are living in another time zone because you spoke about later this evening. In my country it was posted afternoon.
That \375 worked as replacement for ˛ by the way.
Please add one 6 to my postcount and I'm tha Beast!
This signature was written when my postcount was 66
08-20-2006 09:23 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On