1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
double M,Mb,v, CfDraft, Pair,k,Cr,g, Proll, timeTravel, energyTotal, Psec;
int distance;
cout<<"Enter the mass of the rider "<<endl;
cin>>M;
cout<<"Enter the mass of the bike "<<endl;
cin>>Mb;
cout<<"Enter the velocity "<<endl;
cin>>v;
cout<<"Enter the coefficient of drafting "<<endl;
cin>>CfDraft;
k = 0.18;
Cr = 0.001;
g = 9.8;
Pair = (k*CfDraft)*pow(v,3);
Proll = Cr*g*(M+Mb)*v;
Psec = Pair + Proll;
//cout<<Psec<<" W"<<endl;
cout<<fixed<<setprecision(0)<<Psec<<" W"<<endl;
cout<<"Enter the distance in kilometers for the rider to travel "<<endl;
cin>>distance;
timeTravel = (distance*1000)/v;
energyTotal = Psec * timeTravel;
//cout<<energyTotal<<endl;
cout<<fixed<<setprecision(0)<<energyTotal<<endl;
/*This is how it looks when I set Psec and energyTotal to int:
double M,Mb,v, CfDraft, Pair,k,Cr,g, Proll, timeTravel;
int energyTotal, Psec, distance;
cout<<"Enter the mass of the rider "<<endl;
cin>>M;
cout<<"Enter the mass of the bike "<<endl;
cin>>Mb;
cout<<"Enter the velocity "<<endl;
cin>>v;
cout<<"Enter the coefficient of drafting "<<endl;
cin>>CfDraft;
k = 0.18;
Cr = 0.001;
g = 9.8;
Pair = (k*CfDraft)*pow(v,3);
Proll = Cr*g*(M+Mb)*v;
Psec = Pair + Proll;
cout<<Psec<<" W"<<endl;
//cout<<fixed<<setprecision(0)<<Psec<<" W"<<endl;
cout<<"Enter the distance in kilometers for the rider to travel "<<endl;
cin>>distance;
timeTravel = (distance*1000)/v;
energyTotal = Psec * timeTravel;
cout<<energyTotal<<endl;
//cout<<fixed<<setprecision(0)<<energyTotal<<endl;
*/
return 0;
}
|