Double Error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Double Error

 
0
  #1
Nov 28th, 2008
Hey again guys and gals,

getting a really weird error when i attempt to print out doubles

in my program i have to store several double values, but when ever i print then out all i get is

-9.25596e+061 instead of what should be printed out.

  1. string line;
  2. stringstream stream;
  3. cout << "Please Enter the Mortgage Ammount:" << endl;
  4. getline(cin,line);
  5. stream << line;
  6. stream >> mortgageAmmount;
  7. cout << "Please Enter the Mortgage Term in Years: " << endl;
  8. getline(cin,line);
  9. stream << line;
  10. stream >> mortgageTerm;
  11. cout << "Please Enter the Interest Rate: " << endl;
  12. getline(cin,line);
  13. stream << line;
  14. stream >> interestRate;

thats the code that receives the input mortgageTerm, interestRate and mortgageAmmount are all stored as doubles.

  1. cout << "Mortgage Ammount: " << mortgageAmmount << " GBP" << endl
  2. << "Mortgage Term: " << mortgageTerm << " Years" << endl
  3. << "Interest Rate: " << interestRate << "%" << endl

is the code that prints out the data.

in my test run i entered
mortgageAmount as 20,000
mortgageTerm -9.25596e+061
interestRate -9.25596e+061

and it prints out
mortgageAmount as 20,000
mortgageTerm 20
interestRate 5.5

thanks in advance for any help

-Midi
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 445
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 69
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: Double Error

 
0
  #2
Nov 28th, 2008
Why are we not collecting the inputs into some 'double' variables directly? why so many string operations?
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Re: Double Error

 
0
  #3
Nov 28th, 2008
because i read that reading in strings first then converting by using the stream works better than cin due to problems with cin.

i'm currently rewriting it to use cin now.

when reading in my integers for my menu using strings and streams works perfectly.

i'll post back when i've tried it with cin

-Midi

edit: I've changed them all to cin and it works, guess it was me just trying to make it more complex than it really is. still not sure why mortgageAmount worked and the others didnt even though they used the same read method and were all doubles but it works now so i wont spend long wondering why it didnt work
Last edited by midimatt; Nov 28th, 2008 at 1:31 am. Reason: Update due to my over complexity
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC