How would I be able to make the program loop so that it allows me to repeatedly test the function during the output instead of running it over and over each time for different values of Z? Any ideas? Thanks
#include <iostream>
double f(double x);
int main()
{
double z;
cout<<"Enter a value for z\n";
cin>>z;
cout<<f(z)<<endl;
}
double f(double x)
{
if(x>0){
double sum=0;
for(int i=1;i<=(int)(x);i++){
sum+=i;
}
return sum;
}
else if(x==0){
return 0;
}
else{
return x+2;
}
}

New Topic/Question
Reply




MultiQuote




|