evetsleep

DO Example

Oct 25th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1.     #include <iostream>
  2.  
  3.     using namespace std;
  4.  
  5.     int main ()
  6.     {
  7.         int startNumber; //Initialize as an integer.
  8.         int counter = 0; //Initialize with a value of 0.
  9.         int result = 0; //Initialize with a value of 0.
  10.         const int endNumber = 5000; //Initialize with a constant value of 5000.
  11.  
  12.         //Ask the user for a number to use for calculations and store that in
  13.         //the startNumber variable.
  14.         cout << "Please enter a starting number: ";
  15.         cin >> startNumber;
  16.        
  17.         //Add result + start number until the value of result is equal to or greater than
  18.         //the value of endNumber.  Increment a counter while doing it so we can see how
  19.         //many times it took to get there.
  20.         do
  21.         {
  22.             result = result + startNumber;
  23.             counter++;
  24.         } while (result < endNumber);
  25.  
  26.         //Return the end result
  27.         cout << "It took " << startNumber << " added to itself " << counter << " times before it was greater than or equal to " << endNumber << "\n";
  28.         cout << "The end value was: " << result;
  29.    
  30.         //Send an exit code (or error level) of 0.
  31.         return 0;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment