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

Write a C++ program that creates three arrays named prices, units and amount. Ea

ID: 639725 • Letter: W

Question

Write a C++ program that creates three arrays named prices, units and amount. Each array should hold five doubles. Using a for loop and a cin statement, have your program accept and store in the appropriate array a price followed by the number of units. Calculate the amount and store it in the amount array. After entering five prices and amounts your program should display a table with totals as shown:

        Price    Units    Amount

         9.00     1.00      9.00

         8.00     2.00     16.00

         7.00     3.00     21.00

         6.00     4.00     24.00

         5.00     5.00     25.00

Total:   35.00     15.00    95.00

Press any key to continue . . .     

Explanation / Answer

#include<iostream>
int main()
{

   double prices[5],units[5],amount[5];
   double totalPrice=0,totalUnits=0,totalAmount=0;
      
   cout<<"Enter Details ";
   for(int i=0;i<5;i++)
   {
       cout<<"Enter Price of item "<<(i+1)<<" :";
       cin>>prices[i];
       cout<<"Enter number of units of item "<<(i+1)<<" :";
       cin>>units[i];  
   }
  
   for(int i=0;i<5;i++)
   {
       amount[i] = prices[i]*units[i];
       totalPrice = totalPrice + prices[i];
       totalUnits = totalUnits + units[i];
       totalAmount = totalAmount + amount[i];
   }

  
  

   cout<<" Price Units Amount ";
   for(int i=0;i<5;i++)
   {
       cout<<" "<<prices[i]<<" "<<units[i]<<" "<<amount[i]<<endl;
   }
   cout<<"Total: "<<totalPrice<<" "<<totalUnits<<" "<<totalAmount<<endl;

   return 0;
}

===============================================

Input and output

===============================================

Enter Details
Enter Price of item 1 :9
Enter number of units of item 1 :1
Enter Price of item 2 :8
Enter number of units of item 2 :2
Enter Price of item 3 :7
Enter number of units of item 3 :3
Enter Price of item 4 :6
Enter number of units of item 4 :4
Enter Price of item 5 :5
Enter number of units of item 5 :5
Price Units Amount
9 1 9
8 2 16
7 3 21
6 4 24
5 5 25
Total: 35 15 95
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote