Some of you may have seen the program in which I outputted a list of squared numbers starting from 0 up until that given number. This time I am trying to do the same thing with a list of doubles. I believed the concept was about the same but I was proven wrong when my program sucked up every last bit of my memory. I think my problem may be where I am using my loops and how it deals with the doubles. Thanks for the help!
main
sourceCode:#include "squareddoubleheader.h" #include <conio.h> #include <iostream> #include <vector> using std::cin; using std::cout; using std::vector; int main(){ cout << "What is the double you wish to square? "; double doub; cin >> doub; vector<double> doubled; squareddouble(doub, doubled); for(int i = 0; i <= doub; i++){ cout << i << " " << doubled[i]; } cout << "Press enter to continue.."; _getch(); return 0; }
Code:#include "squareddoubleheader.h" #include <vector> using std::vector; void squareddouble(double doub, vector<double>& squaredoub){ for(double d = 0.0; d <= doub; doub++){ squaredoub.push_back(d*d); } }



LinkBack URL
About LinkBacks



