samedi 24 septembre 2022

How could you write a loop to compute sqrt(2 + sqrt ( 2+ (sqrt ( 2 +...) n times

//The n is input as an integer between 1 and 30.I have no idea where to start for the sqrt function. We are asked to only use input/output statements, variables, selection statements, and loops. Using functions or arrays is not allowed because we haven't learned them so far. So far I have this: This makes sure the user enters a valid integer but I don't know where to go from here.

using namespace std;
int kvalue;

int main() {
 cout << "Welcome to the Approx PI program.\n";
 cout << "Please enter in a value for k...";
 cin >> kvalue;


 // validate the input of the user
 while (kvalue<1 || kvalue>30)
 {
     cout << "Please enter a valid k value...";
     cin >> kvalue;

 }

Aucun commentaire:

Enregistrer un commentaire