Array Help :/

My assignment is as follows:
4. (Program) Write, compile, and run a C++ program that stores the following numbers in an
array named prices: 9.92, 6.32, 12.63, 5.95, and 10.29. Your program should also create two
arrays named units and amounts, each capable of storing five double-precision numbers.
Using a for loop and a cin statement, have your program accept five user-input numbers in
the units array when the program is run. Your program should store the product of the corresponding
values in the prices and units array in the amounts array. For example, use
amounts[1] = prices[1] * units[1]. Your program should then display the following
output.

I know this is stating I need 3 arrays. I just did a previous program using arrays and for some reason, I had no trouble getting the program to work correctly and now I'm at a loss of how to set this up exactly..
Thanks in advance for any help in working through this.
-Nikki
Just a word of advice, nobody on this site will do your homework for you. You need to make an attempt at the homework, and if you still can't figure it out, show us the code you've typed. Tell us what you did, what you were thinking, and what specifically you need help with. It's much easier for everybody that way, and you will actually learn something instead of just having someone do your homework for you.
Thank you for your advice, I believe in my previous statement I said "any help in working through this", no where did I say if you could please do my homework for me. I'm sure people have come looking for others to do their work for them but that was not my intention. I was merely looking for a starting point to catalyst my work. What good would it do if I had some one else do my work for and not gain any knowledge to build upon for later assignments and tests?
However I understand why you said what you did, I just wanted to clarify what my intentions were/are.
-Nikki
Ah. I didn't realize you were asking where to start, I though you had written some then just given up. I'll try to help you out.

Try something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int main()
{
    double prices[5] = {/*The list of prices that I'm too lazy to type*/};
    double amounts[5], units[5];
    
    /*You will need a for statement here, but I won't write this for you
    as it is the loop that the whole assignment revolves around.
    
    Basically, find a way to cycle through the numbers 0 - 4 and 
    store the different numbers the user will enter in the amounts[] and units[].
    
    A hint would be that you can use variables in arrays i.e. amounts[var]*/
}


Let me know if this helps at all.
Last edited on
Thank you very much, I ended up getting some help on the back end with working through it. Should I post my work or do you think it will just give someone else the answer?
Again thank you for the starting points, I'm going to write that down for the next assignment so it will help me set up the next...Now I'm onto my other 4 assignments that are now due because I took to long working on a different one ehhh.
I'm going through all of my presentations and the book to try to absorb more information and figure out which aspects I'm not grasping which is causing me to have difficulties.
I had no problems at all with Visual Basic (obv a diff language though). I'm starting to feel a little intimidated.
-Nikki
You can post your work if you like. I will look through it to see if any improvements can be made to further your knowledge of arrays.
#include <iostream>
using namespace std;

int main()
{
double prices[5] = {9.92, 6.32, 12.63, 5.95, 10.29};
double amounts[5]
double units[5];

int i;
for (i=0; i<=4; i++)
{
cout << "Please enter how many you bought of this item:"
cin >> units [i]
}

for (i=0; i<=4; i++)
{
amounts [i] = prices[i]*units[i];
}

total_amounts=0 ; total_units=0

for( i=0; i <=4 ; i++)
{
total_amount= total_amounts + amount[i];
total_units= total_units + units[i];
}

that's all i know :D

- Chirag r.
Last edited on
Topic archived. No new replies allowed.