Quick data type question

In the code below I am taking a double and turning it into a integer, is that correct or just dropping everythng after the decimal? And then multipling two different data types? I wrote it I am just not sure I understand it completely.

double parentsBonds = 0.50;
double bondsPurchased;
int dollarNoBonds;
double parentBondsPurchased;

dollarNoBonds = static_cast<int>(bondsPurchased);
parentBondsPurchased = dollarNoBonds * parentsBonds;

cout<<"Parents Purchase of Bonds: "<<parentBondsPurchased<<endl;



entire program if it helps:
#include<iostream>

using namespace std;

int main()
{
double payRate;
double hoursWorked;

double taxes = 0.14;
double clothesOther = 0.11;
double savingBonds = 0.25;
double parentsBonds = 0.50;
double grossIncome;
double netIncome;
double schoolSupplies;
double afterIncome;
double bondsPurchased;

int dollarNoBonds;
double parentBondsPurchased;


cout<<"Enter pay rate: "<<endl;
cin>>payRate;
cout<<"Enter number of hours worked: "<<endl;
cin>>hoursWorked;

grossIncome = payRate * hoursWorked;
netIncome = grossIncome - (grossIncome * taxes);
schoolSupplies = netIncome * clothesOther;
afterIncome = netIncome - schoolSupplies;
bondsPurchased = afterIncome * savingBonds;

cout<<"Income Before Taxes: "<<grossIncome<<endl;
cout<<"Income after Taxes: "<<netIncome<<endl;
cout<<"Cost of School Supplies Purchased: "<<schoolSupplies<<endl;
cout<<"Cost of Bonds Purchased: "<<bondsPurchased<<endl;

dollarNoBonds = static_cast<int>(bondsPurchased);
parentBondsPurchased = dollarNoBonds * parentsBonds;

cout<<"Parents Purchase of Bonds: "<<parentBondsPurchased<<endl;

system("pause");

}

I am taking a double and turning it into a integer, is that correct or just dropping everythng after the decimal

Yes. Everything after the decimal is dropped.


And then multipling two different data types?

If you multiply double with an int then int is converted to a double. For ex.
int i = 10; double d = 12.5;
Now when i is multiplied with d, then i will be converted to 10.0

Topic archived. No new replies allowed.