Thread: number ouput problem...

  1. #1
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138

    number ouput problem...

    Hello everyone, heres my problem...

    When I enter values into my console app too big, it converts my numbers to things like 9.9e+010, thats for 99000000000. My qiestion is, is theres a variable type that will display that many digits? Or is it not even a matter of variable type? Im currently using long double. Thanks

    edit: heres the code

    Code:
    //ResistorCalculator.cpp
    
    #include <iostream.h> using namespace std;
    #include <math.h>
    #include <conio.h>
    
    
    int main()
    {
    	cout.setf(ios::fixed);
    	cout.setf(ios::showpoint);
    	long double color1, color2, color3, total, temp, ten, temp2, totalk, tolerance;
    	int color4;
    	cout << "9999999999999999999999999999999999999999999999999999";
    	ten = 10;
    
    	cout << "First 3 Color Key:" << endl << "Black-0 Brown-1 Red-2 Orange-3 Yellow-4 Green-5" << endl << "Blue-6 Violet-7 Gray-8 White-9 Gold-10 Silver-11" << endl << endl; 
    	cout << "Enter first color: ";
    	cin >> color1;
    	cout << "Enter second color: ";
    	cin >> color2;
    	cout << "Enter third color: ";
    	cin >> color3;
    	
    	cout << "Fourth Color Key: Gold-0 Silver-1 None-2" << endl << endl;
    	cout << "Enter fourth color: ";
    	cin >> color4;
    
    	cout<< endl;
    	
    	switch (color4)	
    
      {	   
    
       case 0:
    	   
    	    tolerance =5;
    
    	    break;	 
    
       case 1:
    
    	    tolerance = 10;	 
    
            break;	
    
       case 2: 
    	   
    	    tolerance = 20;	 
    
            break;	 
    
      default: 	  
    
            cout << "Invalid Input for fourth color tolerance value may be wrong." << endl << endl;
    	}
    	
    	
    	temp = color1*10+color2;
    	temp2 = pow(ten,color3); 
    	
    	total= temp*temp2;
    	totalk = total/1000;
    
    	cout << "Your resistor's value is " << total << " or " << totalk<< "k ohm's with a tolerance of +/- " << tolerance << "%." << endl << endl;
    
    	return 0;
    
    }
    Last edited by o0obruceleeo0o; 11-16-2002 at 09:13 PM.

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    I can help over AIM

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    You are outputting all those 9's as a string. Yes, that will show, always. Aside from that I had no problems O.o

  4. #4
    Registered User jawwadalam's Avatar
    Join Date
    May 2002
    Posts
    131
    I think it is the case of the variable... because.. it is long double ... but there can be a method to display it in the other way... as u intended to display
    Last edited by jawwadalam; 11-16-2002 at 09:26 PM.
    One day you will ask what more important to you..
    I will say my life..
    and You will leave me with even knowing
    that
    You are my Life (L)

  5. #5
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    the variable total is the one I was having problems with. Ignore the 9's . What type of variable should it be? Thanks

  6. #6
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    the long double is storing the wanted number, and your number is the range of what a long double can take, but it's just outputing it in a different way. It's the same.
    Is that your question.

  7. #7
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    Does anyone know how to output it the normal way? Thanks again for replies!!

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    You may be looking to add cout << setprecision(x); where x = number of decimal places desired. Requires #include <iomanip.h>.

    Your code is non-standard but compiles and executes fine on Borland 5. Just displays a ton of zeroes without setprecision().

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Random Number Range Problem.
    By xamlit in forum C Programming
    Replies: 11
    Last Post: 01-26-2006, 12:55 PM
  3. small problem
    By ucfmustang in forum C Programming
    Replies: 1
    Last Post: 02-10-2003, 04:55 PM
  4. problem with my prime number program
    By datainjector in forum C Programming
    Replies: 4
    Last Post: 07-12-2002, 12:30 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM