question archive Create a program in C++ will use a for loop to complete the following: Ask the user how much the buyer is paying for apples per pound

Create a program in C++ will use a for loop to complete the following: Ask the user how much the buyer is paying for apples per pound

Subject:Computer SciencePrice:3.86 Bought8

Create a program in C++ will use a for loop to complete the following:

  • Ask the user how much the buyer is paying for apples per pound.
  • Ask the user how many baskets of apples they picked.
  • For each basket of apples ask:
  • How much did basket #_ weigh?
  • Your program should place a number associated with the appropriate basket.
  • Ex. If the user picked 2 baskets of apples, your program should ask:
  • How much did basket #1 weigh?
  • How much did basket #2 weigh?
  • Display to the user how many total pounds of apples they picked.
  • Display to the user the amount the buyer should pay them for their picked apples.

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Code:

#include <iostream>
using namespace std;

int main()
{
   int amountPerPound,numberOfBaskets, weight; //variable to store the amount, number of basket and weight of each basket
   int totalWeight = 0; //variable to store the sum of weight, initialized to 0
   //Prompting user to enter the amount to be paid per pount and total number of baskets
   cout<<"How much are you paying for apples per pound? ";
   cin>>amountPerPound;
   cout<<"How many baskets of apples you picked? ";
   cin>>numberOfBaskets;

  //using for loop to get weight for each basket, for loop will run numberOfBaskets time
   for(int i=1;i<=numberOfBaskets;i++)
   {
    cout<<"How much did Basket #"<< i <<" weigh? ";  //Askinf user to enter weight of i basket ???
    cin>>weight; //store weight
    totalWeight = totalWeight+weight; //add weight to the sum variable
   }
  //Print the total weight and total amount to be paid
   cout<<"Total pound of apples you picked: "<<totalWeight<<"\n";
   cout<<"Amount to be paid for the apples picked: "<<totalWeight*amountPerPound;  
       


    return 0;
}

Please see the attached file for the complete solution

Related Questions