Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use

Demo Working with Variables

Sample program:
(TASK:  Write a program to fill 2 integer variables with the number of 17 year old girls and boys in the class, establish a constant age variable = 17, and perform multiplication of the constant times the variables producing the total number of years.  All of the students in the class are 17 years old.)

#include <iostream.h>
int main(void)
{
     int girls = 15;
     int boys = 19;
     const int age = 17;  //cannot be changed or reassigned within this program
     cout<< "Total number of years will be "<<age*girls<<" and  "<<age*boys<<".";
     cout<<endl<<endl<<endl;
     return 0;
}

 

Screen Display

Total number of years will be 255 and 323.

 

Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use