GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Jul-2003, 13:40
Charunks Charunks is offline
New Member
 
Join Date: Jul 2003
Posts: 4
Charunks is an unknown quantity at this point

a question about / operator


Hey guys, I'm learning C++. I've written my own first programs and I noticed this.

how come :

statement:
C=a/b;

if a/b<1 the program will say C=0. Even when I defined C as float.

Should you define C as another type, or can't c++ calculate with numbers -1 > 0 < 1 ?

thnx
  #2  
Old 21-Jul-2003, 02:40
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
If C is defined as a float, it should have a few decimal points.

Floats won't throw away that much info.

For curiosity, try making C a double.

How do you print out the answer? If you're using printf, and it's outputting an integer %d, it probably is rounding it for you.

Garth Farley
  #3  
Old 21-Jul-2003, 11:38
Charunks Charunks is offline
New Member
 
Join Date: Jul 2003
Posts: 4
Charunks is an unknown quantity at this point
here's a part:
CPP / C++ / C Code:
float Omtrek(int x) // surroundingdistance
{
	return x*PI;
}

float Oppervlakte(int x) // area of a circle
{
	return (PI*x*x);
}
float OppervlakteBol(int x) area of the outside of the sphere
{
	return (4*PI*x*x);
}
float Inhoud(int x) // 'contents' of the circle
{
	return (4*PI*x*x*x/3);
 /* this is a small problem. If I write 4/3*PI*x*x*x the anwser is wrong. Also if I devide diameter into two to get the radius and the diameter < 2 the radius would be 0*/
}
I'm printing with the cout << " "; function

I will try making some floats double's.

thnx
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
a C input question.. tmike C Programming Language 2 19-Sep-2003 02:39
a C input question tmike C Programming Language 1 16-Sep-2003 02:31
char to operator calculus87 C++ Forum 3 04-Sep-2003 10:05
a noobish compiler question Charunks C++ Forum 5 03-Sep-2003 02:18
Operator overloading (not happening) gmn C++ Forum 11 30-Aug-2003 08:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:22.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.