Question about exponents

This is a discussion on Question about exponents within the C++ Programming forums, part of the General Programming Boards category; Here's the code Code: #include <iostream> using namespace std; main(){ int x; x = 5 * 45e-6; cout<< x; } ...

  1. #1
    Registered User
    Join Date
    May 2006
    Location
    in your head
    Posts
    49

    Question about exponents

    Here's the code

    Code:
    #include <iostream>
    
    using namespace std;
    
    main(){
    int x;
    x = 5 * 45e-6;
    cout<< x;
    
    }

    I need to get an answer with an exponent in it like for example the answer in the program is 0.000225 but i need an answer like this 2.25e-4 how can i do that?... any idea guys.? tnx in advance...

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,166
    Before anything else, main() returns an int, so declare it as returning an int. Then. x is an int, but you want it to be a double.

    I need to get an answer with an exponent in it like for example the answer in the program is 0.000225 but i need an answer like this 2.25e-4 how can i do that?
    Before printing x, set:
    Code:
    cout.setf(ios::scientific);
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    or you could do

    Code:
    cout << scientific << x << endl;
    btw, using an int for these calculations is useless

  4. #4
    Registered User
    Join Date
    May 2006
    Location
    in your head
    Posts
    49
    weeeiiuuhh tnx for the help laserlight and KIBO i really appreciate it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 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

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