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
Subject:Computer SciencePrice:3.86 Bought8
Create a program in C++ will use a for loop to complete the following:
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