Hey i know this program is killer lame i just want opinions on my structure, methods, habits etc. Maybe a better way i could have done something ya know. The comments are pretty explanatory, but i don't think anyone will have trouble figuring this one out.
Code:/* Steve Billington September 26, 2002 DB.cpp Demonstrates two basic functions to user. */ /* Declare preprocessor directives*/ #include <iostream.h> #include <iomanip.h> /* Constant used in if/for example initiated to 5*/ const int MAIN_CONST = 5; /* Constant for first for loop in nest for example*/ const int FIRST_LOOP = 5; /* Constant for nested loop*/ const int SECOND_LOOP = 3; int main () { /* Declare a character variable to hold users input*/ char getinput; /* Declare double variables for nested for example*/ double input,final; /* As user for a choice of which to demonstrate and store in variable "getinput"*/ cout <<"To see an example of one of the following type the appropriate letter and press enter :"<<endl; cout <<"Manipualting input numbers (A) and for Nested for (B): "; cin >>getinput; /* If statements to decide what example is to be done*/ if (getinput == 'A') { int j; for (j=1; j <= MAIN_CONST; ++j) { cout <<"Enter a number and press enter: "; cin >>input; cout <<"Input was "<<input; final += input; cout <<"Final is "<<final; } } if (getinput == 'a') { int j; for (j=1; j <= MAIN_CONST; ++j) { cout <<"Enter a number and press enter: "; cin >>input; cout <<"Input was "<<input<<endl; final += input; cout <<"Final is "<<final<<endl; } } if (getinput == 'B') { double output; int j2,j3; for (j2=1; j2 <=FIRST_LOOP; ++j2) { for (j3=1; j3 <=SECOND_LOOP; ++j3) cout <<j2<<endl; cout <<j3<<endl; output = j2 * j3; cout <<endl; cout <<output; } } if (getinput == 'b') { double output; int j2,j3; for (j2=1; j2 <=FIRST_LOOP; ++j2) { for (j3=1; j3 <=SECOND_LOOP; ++j3) cout <<j2<<endl; cout <<j3<<endl; output = j2 * j3; cout <<endl; cout <<output; } } /* Make nice amount of room so screen is easily read*/ cout <<endl; cout <<endl; cout <<endl; cout <<endl; /* Thank the user for trying the program*/ cout <<"Thanks for useing my program!"<<endl; /* Return value for main*/ return 0; }



LinkBack URL
About LinkBacks



