// Move the indicated code into functions. #include <iostream> using namespace s
ID: 3934523 • Letter: #
Question
// Move the indicated code into functions. #include <iostream> using namespace std; int main() { double jedi_level; int age; int weight; int mcc; // TODO - write a void function to print out to console this welcome message cout << "Welcome to my fabulous Jedi power level calculator!" << endl << "This program will take your age, weight, and" << endl << "midichlorean count and return your Jedi power level!" << endl << endl; // TODO - write a function that will prompt the user for his/her age, // weight, and midicholrean count. Then calculate and return their // jedi level (returns a double). Remember to assign the retuned value // to the variable 'jedi_level'. cout << "please enter your age : "; cin >> age; cout << "please enter your weight : "; cin >> weight; cout << "please enter your midicholrean count : "; cin >> mcc; jedi_level = static_cast <double>(mcc * age) / (weight * weight); // this should remain inside your main function cout << "Your Jedi Level is : " << jedi_level; return 0; }
Explanation / Answer
#include <iostream>
#include<math.h>
using namespace std;
void printMessage(){
cout << "Welcome to my fabulous Jedi power level calculator!" << endl
<< "This program will take your age, weight, and" << endl
<< "midichlorean count and return your Jedi power level!"
<< endl << endl;
}
double jediLevel(){
int age, mcc;
double weight, jedi_level;
cout << "please enter your age : ";
cin >> age;
cout << "please enter your weight : ";
cin >> weight;
cout << "please enter your midicholrean count : ";
cin >> mcc;
jedi_level = static_cast <double>(mcc * age) / (weight * weight);
return jedi_level;
}
int main()
{
double jedi_level;
printMessage();//this function will print the welcome message
jedi_level=jediLevel();//this method calculate jediLevel
cout << "Your Jedi Level is : " << jedi_level;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.