I'm trying to write a program to fill an array with the following conditions:
1:) User defines number of rows up to 25. (array[25])
2:) User defines the first number to start with ( array[0] ).
3:) User defines the increment of the first number to fill the rest of the arrays elements (array[1-n])
I have been trying many variations and tutorials but I haven't been able to crack it.
Here's what I have so far:
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 29 30 31
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
int main()
{
int index[25];
int incr, elementnum, value = 0;
cout << "How many elements? (Up to 25) > ";
cin >> elementnum;
cout << endl;
cout << "Number to start with? > ";
cin >> value;
cout << endl;
cout << "Increment? > ";
cin >> incr;
for (int i = 0; i < elementnum; i++){
int x = value + incr;
index[i] = x;
cout << x << "\n";
}
system("pause");
return 0;
}
|
In this instance I get if the user puts in 4, 3, 2 it displays
5
5
5
5
It is performing the addition 1 time and putting it into array[0] then repeating but does not increment.
Once this is complete I'm going to have to use each element value to figure square, square root, cube, cube root, in different arrays so any advance advice is welcome also.