CSCI 131 Techniques of Programming--Spring 2014

    Home | | Schedule | | Assignments | | Lectures | | Resources

    Solution to Lab 4 forerr.cc

    //*********************************************************************
    // forerr.cc
    //     Author: King/Royden
    //     Date: February 23, 2014
    //     Class:   CSCI 131
    //     Purpose:  This program demostrates the use of for loops.
    //     Input:    None
    //     Output:   (to standard output) The loop counters for three loops
    //*********************************************************************
    
    #include <iostream>
    using namespace std;
    
    int main( void )
    {
        int   i;                   // counter for the first loop
        char  ch;                  // counter for the second loop
        float r;                   // counter for the third loop
        
        //  Prints the values from 1 to 5 inclusive
        
        for (i = 1; i < 6; i++) {
            cout << "Within the first loop i has the value " << i << endl;
        } // for
      
        //  Prints the letters from A to E inclusive
        
        for (ch = 'A'; ch < 'F'; ch++) {
            cout << "Within the second loop ch has the value " << ch << endl;
        } // for
        
        //  Prints the values from 0.0 to 1.0 inclusive incrementing by 0.1
        
        for (r = 0.0; r <= 1.0; r = r + 0.1) {
            cout << "Within the third loop r has the value " << r << endl;
        } // for
        
      return 0;
    } // main
    
    
    

    Home | | Schedule | | Assignments | | Lectures | | Resources



    CSCI 131: Techniques of Programming
    Last Modified: February 23, 2014
    Page Expires: October 12, 2014