aight so im trying to write a program that takes in one value of an array and quaruples it each time for 6 times, i cant get the rest of the numbers to quadruple besides the first, plz help. heres my code:
#include<iostream>
using namespace std;
int main()
{
const int num = 6;
float myArray[6];
float sum = 0;
float quad = 0;
cout << "Please enter a number " << endl;
cin >> myArray[0];
Firstly, your code only takes in one number. There are no "rest of the numbers". You only put a number into myArray[0], so myArray[1] to myArray[5] will have garbage values in.
That said, when your code gets round to multiplying the numbers, it always multiplies myArray[0]. sum = 4*myArray[0];
heres the question - "Define a float type array with 6 values using a constant value variable. The user should be prompted to fill the first value then the array should be populated by quadrupling the previous value in the array"
#include<iostream>
usingnamespace std;
#define MAX_SIZE (6)
int main()
{
float myArray[MAX_SIZE];
float myNum;
cout << "Enter first Number: ";
cin >> myNum;
//assign the number to the first element of array
myArray[0] = myNum;
//populate the array
for (int i = 0; i < MAX_SIZE; i++)
{
myArray[i + 1] = 4 * myArray[i];
cout << myArray[i] << endl;
}
cin.get();
return 0;
}
The problem with your code is at sum = 4*myArray[0];
where you are using only
myArray[0]
and storing it to sum without making any changes to it.