CPP Cafe

The Menu

 

Home -> Menu ->Static Casting

 

Static_Casting

output

 


#include <iostream.h>
#include <stdlib.h>
/* Prompts user to enter three decimal numbers
Prints the three decimal numbers
converts each to the nearest integer
adds the three integers
prints the sum and average of the three integers
*/
void round(){
double numa;
double numb;
double numc;
double numd;
double nume;
double sum;
double avg;
double num1;
double num2;
double num3;
double num4;
double num5;

cout<<"Please enter the first decimal number:"<<endl;
cin>>num1;
numa = num1 - static_cast<int>(num1);
if(numa < .5)

numa = static_cast<int>(num1);
else
numa = static_cast<int>(num1) + 1;
cout<<numa<<endl;
cout<<"Please enter the second decimal number"<<endl;
cin>>num2;
numb = num2 - static_cast<int>(num2);
if(numb < .5)

numb = static_cast<int>(num2);
else
numb = static_cast<int>(num2) + 1;
cout<<numb<<endl;

cout<<"Please enter the third decimal number"<<endl;
cin>>num3;
numc = num3 - static_cast<int>(num3);
if(numc < .5)

numc = static_cast<int>(num3);
else
numc = static_cast<int>(num3) + 1;
cout<<numc<<endl;
cout<<endl;

cout<<"The integers are:"<<" "<<numa<<" "<<numb<<" "<<numc<<endl;
sum = numa + numb + numc;
cout<<"The sum of the integers is:"<<" "<<sum<<endl;
avg = sum / 3;
cout<<"The average of the integers is:"<<" "<<static_cast<int>(avg)<<endl;

}

int main()
{
round();
system("PAUSE");
return 0;
}