If I have an array that is declared and used in a for loop so the user input its value how can I declare new array which his | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If I have an array that is declared and used in a for loop so the user input its value how can I declare new array which his

Elements are divided by the first array (declaring an array using another one)

14th May 2019, 7:06 AM
Manar Ksm
Manar Ksm - avatar
13 Answers
+ 2
const int size = 10; int A[size], B[size]; for (int index = 0; index < size; index++) { // read user input cin >> A[index]; } if (A[size] == 0) { // division by zero } for (int index = 0; index < size; index++) { // your calculation B[index] = A[index] / A[size - 1]; }
14th May 2019, 12:37 PM
Daniel Adam
Daniel Adam - avatar
+ 3
Do you mean there is a second array with numbers already in it? Or are you asking users for two numbers, dividing them, and putting them in an array? Do you have any code to show us so we can understand better?
14th May 2019, 7:28 AM
Rincewind
Rincewind - avatar
+ 3
Short answer: 1) declare Array A,B of size 10 2) read 10 values into A 3) iterate through A, devide by A[9], store to same position of B (special case: devision by 0) Done.
14th May 2019, 7:40 AM
Daniel Adam
Daniel Adam - avatar
+ 3
As Daniel Adam said, it would be far better for you to show us your code so we can see what you've actually tried; if you haven't already tried, it's unfair to expect anyone to write it for you from scratch.
14th May 2019, 7:45 AM
Rincewind
Rincewind - avatar
+ 3
Manar Ksm The code you submitted is more like an error correction task than the code you made.😕
14th May 2019, 12:29 PM
Solo
Solo - avatar
+ 2
Can you please provide your current state of the Code. That's easier to adopt or give hints how to solve it. Thx.
14th May 2019, 7:37 AM
Daniel Adam
Daniel Adam - avatar
+ 1
Sorry, but I can figure out what you're question may be.
14th May 2019, 7:08 AM
Daniel Adam
Daniel Adam - avatar
+ 1
Manar Ksm - step 2) and 3) are Loops. (You can do this manually but it would be boiler plate code .. and imagine 100 inputs).
14th May 2019, 7:54 AM
Daniel Adam
Daniel Adam - avatar
0
First I declare an array A of size 10 Then I ask the user to enter the array values using for loop Now I should divides all the array values by the value of the last element of the array and put the value into new array B The last step I don't know how to do it :(
14th May 2019, 7:33 AM
Manar Ksm
Manar Ksm - avatar
0
The third step should be done in the for loop where I asked the user to enter 10 values?!
14th May 2019, 7:43 AM
Manar Ksm
Manar Ksm - avatar
0
#include "stdafx.h" #include <iostream> using namespace std; int main() { int A [10]; double B [10]; int newArray; for (int i = 0; i < 10; i++) { cout << "please enter an integer numbers" << endl; cin >> A[i]; newArray = A[i]; } for (int j = 0; j < 10; j++) { B[j] = {newArray/A[10]}; cout << B[j] << endl; } return 0; } devisfun thats my code And I think that Daniel Adam understood that am stuck in declaring B not in need for someone to do my code without even trying for that :)
14th May 2019, 8:08 AM
Manar Ksm
Manar Ksm - avatar
0
And that's why I need help :(
14th May 2019, 12:31 PM
Manar Ksm
Manar Ksm - avatar
0
Daniel Adam Thanks so much :-D
14th May 2019, 12:40 PM
Manar Ksm
Manar Ksm - avatar