Thread: question: how to divide two floats

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    1

    question: how to divide two floats

    I've looked around on the net and in a couple books, but I can't find a way in C++ to divide two floats. Anybody have ideas?

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    It's simple.. make 2 floats and use the division operator.

    Code:
    #include <iostream>
    
    int main() {
    	float a = 5.f;
    	float b = 2.2f;
    	float c = a/b;
    
    	std::cout << c << '\n';
    
    	return 0;
    }
    Perhaps you are stumbling over a more difficult problem, like changing ints to floats before the division, so things like 7/2 would result in the float value of 3.5 rather than the int value of 3?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM