| | |
Double Error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
thats the code that receives the input mortgageTerm, interestRate and mortgageAmmount are all stored as doubles.
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
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.
C++ Syntax (Toggle Plain Text)
string line; stringstream stream; cout << "Please Enter the Mortgage Ammount:" << endl; getline(cin,line); stream << line; stream >> mortgageAmmount; cout << "Please Enter the Mortgage Term in Years: " << endl; getline(cin,line); stream << line; stream >> mortgageTerm; cout << "Please Enter the Interest Rate: " << endl; getline(cin,line); stream << line; stream >> interestRate;
thats the code that receives the input mortgageTerm, interestRate and mortgageAmmount are all stored as doubles.
C++ Syntax (Toggle Plain Text)
cout << "Mortgage Ammount: " << mortgageAmmount << " GBP" << endl << "Mortgage Term: " << mortgageTerm << " Years" << endl << "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
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
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
![]() |
Similar Threads
- conversion from string to double error (VB.NET)
- cannot find server or DNS error (Web Browsers)
- error C2664 (C++)
- Debugging error C2653 (C++)
- decimal counting of a double... howto? (Java)
- Error message missing bridge.dll when starting windows (Viruses, Spyware and other Nasties)
- How to Perform Disk Error Checking in Windows XP (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: Opening a FileDialog
- Next Thread: DFS goes into infinite loop
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





