Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Parallel Arrays - Write a c++ program that stores the following numbers in an ar

ID: 3770358 • Letter: P

Question

Parallel Arrays - Write 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 additional arrays named units and amounts, each capable of storing 5 double-precision numbers. Using a for loop and a cin statements, have your program accept five numbers from the user and assign them to the units array. Your program should store the product of the corresponding values in the prices and units arrays in the amounts array. For example: amounts[1] = units[1] * prices[1]; You program should use one for loop to accept the units from the user AND calculate the amount values. Then, the program should use a second loop to display all three arrays in a well formatted table.

Explanation / Answer

Here is the code for you. If you have any further queries, just get back to me.

#include <iostream>
using namespace std;

int main()
{
double prices[] = {9.92, 6.32, 12.63, 5.95, 10.29};   //Initializes the prices array.
double units[5];               //Declares the units array of size 5.
double amounts[5];           //Declares the amounts array of size 5.
for(int i = 0; i < 5; i++)   //For each value from 0 to 4.
{
cout<<"Enter the number of units of product #"<<i+1<<": ";
cin>>units[i];               //Reads the units.
amounts[i] = units[i] * prices[i];   //Updates the amounts.
}
for(int i = 0; i < 5; i++)
cout<<"Product #"<<i+1<<" "<<prices[i]<<" "<<units[i]<<" "<<amounts[i]<<endl;
}