Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main ()
- {
- int startNumber; //Initialize as an integer.
- int counter = 0; //Initialize with a value of 0.
- int result = 0; //Initialize with a value of 0.
- const int endNumber = 5000; //Initialize with a constant value of 5000.
- //Ask the user for a number to use for calculations and store that in
- //the startNumber variable.
- cout << "Please enter a starting number: ";
- cin >> startNumber;
- //Add result + start number until the value of result is equal to or greater than
- //the value of endNumber. Increment a counter while doing it so we can see how
- //many times it took to get there.
- do
- {
- result = result + startNumber;
- counter++;
- } while (result < endNumber);
- //Return the end result
- cout << "It took " << startNumber << " added to itself " << counter << " times before it was greater than or equal to " << endNumber << "\n";
- cout << "The end value was: " << result;
- //Send an exit code (or error level) of 0.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment