Honestly most of this is wrong.
I'll start by telling you what is wrong/why it's wrong so hopefully you can try to get an idea of how to fix it.
result = getValues();
This is wrong, because of two reasons.
1) getValues is a void function, it doesn't return anything. If you want to set a double to be equal to the return value of a function, that function should be double. The function could be a float, or another type of integer, but it can't be void.
2) Even if this function was of type double, it's not like return numbers would return the array, it would only return 1 double.
1 2 3 4 5 6 7 8 9 10 11 12
|
void getValues(double numbers)
{
numbers[5];
cout << "please enter five numbers\n";
for ( int i; i < 5; i++)
{
cin >> numbers[5];
}
return numbers;
}
|
This also is wrong.
numbers[5];
means nothing by itself. Your function parameter has a double number passed. This is 1 number, not an array of numbers. Just because you put
numbers[5];
doesn't make it so you're passing an array, that line doesn't mean anything and shouldn't even compile.
Also keep in mind, even if you had successfully passed the array, you still wouldn't be able to access numbers[5]. Here is the reason why.
When you declare
double Numbers[5];
it creates
Numbers[0]
Numbers[1]
Numbers[2]
Numbers[3]
Numbers[4]
However, Numbers[5] doesn't exist.
1 2 3 4
|
for ( int i; i < 5; i++)
{
cin >> numbers[5];
}
|
This code isn't doing what you think it's doing. If numbers was an array that was properly passed through the function, you would change your for loop to
1 2 3 4
|
for (int i=0; i<5; i++)
{
cin >> numbers[i];
}
|
By doing cin >> numbers[5] you are just inputting 5 different values and overwriting them with the last value to the same array index rather than filling in the array. It would just accessing one element of the array.
1 2 3 4 5 6 7 8 9 10 11
|
double doTheMath(char choice, double numbers)
{
if (choice == 'A')
{
for ( int i; i < 5; i++)
{
cout << pow(i);
}
}
}
|
Also, pow doesn't work like that.
If you're just finding the sqrt, make it simple. There's a reason there is a
sqrt(double number)
function. You just need to
#include <math.h>
Also you're missing your
#include <iostream>
for the input and output.
For void getchoice(char choice), you need to realize that if you want that variable to save after you exit that function, you need to pass a reference instead of the variable char choice. This is easy to change, all you need to do is modify that function like so in the prototype and definition change the beginning to
double doTheMath(char &choice, double numbers)
By putting that &, the variable will be changed after you exit that function. Otherwise it wont.
Let me know what you don't understand about this.
I'd help you out by retyping up your code, but the issue is there's so many things wrong with it that I want to make sure you understand what's going on.