I have a program here that doubles .01 64 times. After a while, the numbers start to come out in scientific notation. Is there a type of variable or something that does not do this? I am new to C++, so please make any replies easy to understand. The bold area of the code is the part that displays in scientific notation. Here is the program:
Code:#include <iostream> #include <cstdlib> using namespace std; int first(void); int bonus(void); int main(void) { unsigned int response; cout<<"Checkerboards and Bacterial Reproduction Problem Solver\nby Drew Harris"; do { cout<<"\n\nSelect an Option:\n" <<"1) Answer Questions 1, 2, and 3"<<endl <<"2) Answer the bonus question"<<endl <<"3) Exit"<<endl; cin >>response; switch(response) { case 1: cout<<endl<<endl; first(); break; case 2: cout<<endl<<endl; bonus(); break; default: cout<<endl<<"That is not a menu choice"; } }while(response != 3); cout<<"\nThat's how I solved the checkerboard questions."<<endl; system("pause"); return 0; } int first(void) { double totalmoney = .01; unsigned int cursquare = 1; cout<<"1 | 0.01"<<endl; while(totalmoney<=21.00) { totalmoney = totalmoney * 2; cursquare++; if(totalmoney>21.00) { break; } cout<<cursquare<<" | "<<totalmoney<<endl; } return 0; } int bonus(void) { double totalmoney = .01; unsigned int cursquare = 1; cout<<"1 | 0.01"<<endl; while(cursquare<64) { totalmoney = totalmoney * 2; cursquare++; cout<<cursquare<<" | "<<totalmoney<<endl; } return 0; }




Reply With Quote