We have Homework about loops that displays two computations and increments a variable by the inputted i. These codes run and all is well until I input a=1, b=3 i=0.2
, what happens is that it won't reach to 3
even if the while condition is a<=b
. The only time it works when a=1, b=2, and i=0.2
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double inputI(double i){
for(i=0;i<=0;cin>>i){
cout<<"i must be greater than 0"<<endl;
cout<<"Input i: ";
}
return i;
}
double compX(double s, double b){
double x;
x = s/cbrt(b)+2*pow(s,2);
return x;
}
double compY(double s, double x){
double y;
y = (x+s/x)+3*s;
return y;
}
void display(double x, double y,double a){
cout<<fixed<<setprecision(2)<<a<<"\t";
cout<<fixed<<setprecision(4);
cout<<x<<" "<<y<<endl;
}
int main(){
double x,y,a,b,i;
cout<<"Input a: ";
cin>>a;
cout<<"Input b: ";
cin>>b;
i = inputI(i);
//is there something wrong???
do{
x = compX(a,b);
y = compY(a,x);
display(x,y,a);
a+=i;
}while(a<=b);
}