Hey guys,
in this tutorial, I am going to talk about typecasting. Typecasting is where you can temporarily change the datatype of your variable such as int into floats and floats into ints. Lets say you have a pumpkin farm. You sell pumpkin everyday. Lets see how much money you make averagely each day. Lets go ahead and do that.
#include<stdio.h>
int main() {
float avgProfit;
int priceOfPumpkin = 10;
int sales = 59;
int daysWorked = 7;
avgProfit =((float)priceOfPumpkin * (float)sales/ (float)daysWorked;
{here we have combined int and float datatypes together. That's why we have typed float inside the bracket for every variables otherwise the answer will be in integer.}
printf("Average daily profit: $%.2f", avgProfit);
}
in this tutorial, I am going to talk about typecasting. Typecasting is where you can temporarily change the datatype of your variable such as int into floats and floats into ints. Lets say you have a pumpkin farm. You sell pumpkin everyday. Lets see how much money you make averagely each day. Lets go ahead and do that.
#include<stdio.h>
int main() {
float avgProfit;
int priceOfPumpkin = 10;
int sales = 59;
int daysWorked = 7;
avgProfit =((float)priceOfPumpkin * (float)sales/ (float)daysWorked;
{here we have combined int and float datatypes together. That's why we have typed float inside the bracket for every variables otherwise the answer will be in integer.}
printf("Average daily profit: $%.2f", avgProfit);
}
Comments
Post a Comment