ManualSum9b - <<" is"<< sum<<...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// file: ManualSum.cpp // author: j. dzuback // modified: // date: / /* ********************************************** The program prompts the user for an integer value n, and then finds the sum of the numbers from 0 to n. This variation of a summing loop has a few variations. .. ********************************************** */ #include <iostream> #include <iomanip> #include <string> # using namespace std; u int main() { int sum = 0; int n; int count; char letter; c cout << "Enter an integer (less than 20) and press return: "; cin >> n; cout << endl << endl; c count = 0;// PLEASE COMPLETE THIS STATEMENT -- #1!! c { int sum = 0; int count = 0; { sum = sum+count; count++; } // end of loop } cout <<"The sum of the numbers betweem 0 and " << n << " is " << sum << endl << endl; cout << "\nEnter an integer (less than 20) and press return: "; cin >> n; cout << endl << endl; } // end of loop cout << "Sum of the digits between 0 and " << n
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: << " is: " << sum << endl << endl; < cout<<"\nYou chose to terminate the program, to continue press 'y' if not press 'n': "; cin>>letter; switch(letter) { case 'y': cout << "Enter an integer (less than 20) and press return: "; cin >> n; cout << endl << endl; c while ((n >=0) && (n <= 20)) // if n is from 0 to 20 { int sum = 0; int count = 0; while ((count <= n) && (n<=20)) // do sum { sum = sum+count; count++; } // end of loop } cout <<"The sum of the numbers betweem 0 and " << n << " is " << sum << endl << endl; cout << "\nEnter an integer (less than 20) and press return: "; cin >> n; cout << endl << endl; } // end of loop cout << "Sum of the digits between 0 and " << n << " is: " << sum << endl << endl; break; b case 'n': cout << "*** end of ManualSum ***" << endl << endl; break; b default: cout << "*** end of ManualSum ***" << endl << endl; break; b } return 0; } // end of main...
View Full Document

Page1 / 2

ManualSum9b - <<" is"<< sum<<...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online