// labLoops.cpp for CPS 171 Practice with different kinds of loops // J.Remen Winter 02 // Does not compile at the present time. Note each question is commented out so // students can work on one at a time by removing /* etc. // see the exercise worksheet for discussion of the problems. #include#include #include using namespace std; int main() { cout << "name\n"; int i, num, sum; // 1. Fill in the blanks to make the for loop print the // even numbers between 1 and 100, including the 100 cout << "Question 1\n"; for ( i = ; ; ) cout << i << ' '; cout << endl << endl; /* // 2. Complete the do-while statement that will loop // until the user enters a positive value - test it by // entering a few negative values first. cout << "Question 2\n"; do { cout << "Enter a positive number;"; cin >> num; } while ( ); cout << "After loop num is " << num << endl << endl; */ /* // 3. Complete the loop to sum all the integers from 1 // up to and including num. cout << "Question 3\n"; sum = ; for (i = ) sum = ; cout << "Sum of integers from 1 to " << num << " is " << sum << endl << endl; */ // declare input file and open it ifstream infile; infile.open("labloops.dat"); if(!infile) { cout << "Cannot open input file\n"; return 1; } /* // 4. Read values from the file, sum all negative ones // stop when -999 is read. cout << "Question 4\n"; sum = ; infile >> num; while( ) { } cout << "Sum of negatives is " << sum << endl << endl; */ // If you still have time try questions 5, 6 and 7 on your own return 0; }