Write a C++ program that calculates the total sale for a product. You MUST use a
ID: 3568030 • 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
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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.