#include <iostream>
usingnamespace std;
int main () {
double f;
double m;
int i ;
cout <<"input the value of f ";
cin >> f ;
for(f = 1;f <= 100; f++){
m = f * 3.28;
for (i = 1; i <=100;i++)
break;
cout<< i << " "<< "feet conerted in to meter "<< m <<" \n" ;
}
return 0;
}
-) you get 'f' from the user on line 10
-) but then on line 12 you use 'f' again as a loop counter, which overwrites whatever value the user input.
-) you then have another loop on line 14 that has no body -- except for a break command, so the loop will just exit immediatley
-) then on line 17 you print 'i' as the feet entered (when really, 'f' was the feet entered, not i). Note that 'i' will always be 1 because you set it to 1 on line 14:
for( i = 1 ...
The questions you need to ask yourself are:
* Why do you have these loops?
* What purpose does 'i' serve?
Thanks, it was redundant to ask for the user input when i am specifying the f . i get it.
i tried to use 'i' so that it will give number to each line as there will 100 lines
now i took out the break it stops loop there
but then it becomes the infinite loop. so i put break here:
1 2 3 4 5 6 7 8 9
for(f = 1;f <= 100; f++){
m = f * 3.28;
for (i = 1; i <=100;i++)
cout<< i << " "<< "feet converted in to meter "<< m <<" \n" ;
break; // if i put break here then the first for loop gives only one value which is 3.28. it doesnt get cumulative as it is supposed to be.
}
int main() {
double m;
double f;
int i;
i = 1 ;
for(f = 1.00;f <= 100.00; f++){
m = f * 3.28;
if(i<=100){
cout<< i <<" "<< " feet conerted in to meter "<< m <<" \n" ;
i++; }
}
return 0;
}