Im trying to get this code working in C++. I originally wrote it in Python as:
folds = raw_input('Enter the number of folds of paper')
paperThickness = 0.005;
#0.005 = 1/200
for i in range (0, int(folds)):
paperThickness = paperThickness * 2.0
print 'The thickness after '+folds + ' folds will be', paperThickness, 'cm'
# include <iostream>
usingnamespace std;
int main()
{
int folds;
constdouble paperThickness = 0.005;
cout<<"Enter the number of folds of paper"<<endl;
cin>>folds;
cout<<endl;
double thick = paperThickness;
while(folds >= 0){
thick *=2;
}
cout<<"The thickness after "<<folds<<" folds will be "<<thick<<"cm<<endl;
/* Or
int folds;
double paperThickness;
cout<<"Enter the number of folds of paper"<<endl;
cin>>folds;
cout<<endl;
for(folds =0; folds;){
paperThickness = 0.005;
paperThickness = paperThickness*2.0;
}
cout<<"The thickness after "<<folds<<" folds will be "<<paperThickness<<" cm"<<endl;
*/
return 0;
}
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
setprecision(5); // ( I think)
int folds;
// Im trying to get this code working in C++. I originally wrote it in Python as:
// folds = raw_input('Enter the number of folds of paper')
cout << "Enter the number of folds of paper ";
cin >> folds;
float paperThickness = 0.005;
// #0.005 = 1/200 No idea what this is
// for (i in range (0, int(folds)): would be
for (int i=0;i<folds;i++)
{
int paperThickness = paperThickness * 2.0;
cout << "The thickness after "<< folds << " folds will be " << paperThickness << ", cm" << endl;
}
return 0;
}