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

Write a C++ program that calculates the total sale for a product. You MUST use a

ID: 3568031 • Letter: W

Question

Write a C++ program that calculates the total sale for a product. You MUST use a struct type to store all the information pertaining to the product. The total sale is also computed using the information stored in the struct type. Your program first collects and stores the information in the record of struct type. It then determines the total sale using the information stored in the record. The following shows a sample output of the program.

Enter the product name, product ID, and unit price: iPhone 1234 212.78 // initialization

Enter the number of products sold: 6

The total sale for iPhone of ID 1234 is $1276.68

Explanation / Answer

#include<iostream>

using namespace std;

struct Record{
char productName[20];
int productId;
double unitPrice;
};

int main(){
struct Record r;
int sold;
double totalSale;
cout << "Enter the product name, product ID, and unit price: ";
cin >> r.productName;
cin >> r.productId;
cin >> r.unitPrice;
cout << "Enter the number of products sold: ";
cin >> sold;
totalSale = sold*(r.unitPrice);
cout << "The total sale for iPhone od ID " << r.productId << "is $" << totalSale<<endl;
}

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