Thank you for your very speedy response, and I'm very sorry I didn't write back. I had no PC access until today. I'm grateful for and appreciative of any help, and I will respond back in a timely manner this time.
I removed the unnecessary statements. Thank you! As far as the math, I know that I could simply switch the text statements to correspond to the calculations except that, as far as I know, "pow (x, 2.0);" should multiply the value of x by itself, not square root the number, which is what's happening. I would like to actually understand my mistake, rather than accept it and switch the text around.
Lastly, I need the program to print out the number, square and square root for numbers 1 through 81 (example: 1, 1, 1; 2, 4, 1.41; 3, 9, 1.73; 4, 16, 2; etc.) not a number, its square root, and then its square root squared (4, 2, 4). I tried to accomplish by using the same value for x in each calculation, however it hasn't worked as of yet.
Current code--
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <cmath>
#include <math.h> //Not sure about including math.h
using namespace std;
int calc1 (int x){
return x;
}
double calc2 (double x){
return sqrt(x*1.0); //What's making this return 4? I thought sqrt calculated a number's square root
}
int calc3 (int x){
return pow(x, 2.0); //What's making this return 2, the square root? I thought pow is used for exponents
}
int M1 (int x){
cout << "Number: " << x << endl; //Should display 4
x = calc1 (x);
cout << "Number's square root: " << x << endl; //Should display 2
x = calc2 (x); //Returns "Number". Why?
cout << "Number squared: " << x << endl; //Should display 16
x = calc3 (x); // Returns "square root". Why?
cout << "_________" << endl;
return x;
}
int main (){
int y = 4; // Program currently uses 4 in calculations
y = M1 (y);
}
|