Could you please tell me what i'm doing wrong

// Write a complete C++ program that asks for the price of an item and the quantity purchased, and
// writes out the total cost.

#include <iostream>
using namespace std;

int main() {
    // Declare your variables
    double itemPrice, totalPrice;
    int itemCount;

    // Get user input for item price
    cout << "What is the item price? ";
      cin >> itemPrice;   
    // Get user input for item count
    cout<< "What is the item count? ";
        cin >>itemCount;
    // Calculate the total price
    cout<< "What is the total price? ";
        cin >>totalPrice;
    // Print out the total price to the user
    cout << "Your items cost this much" << totalPrice;
        totalPrice = itemPrice * itemCount;
    return 0;

i don’t understand this bit:

    // Calculate the total price
    cout<< "What is the total price? ";
        cin >>totalPrice;

you know the item price, and the quantity of items (itemCount) the customer bought, so you can calculate the total cost by multiplying the item price times the item count, why prompt the user for total price? The program should calculate that.

if i go to a supermarket, and buy 4 cucumbers costing $1 each, the computer calculates the total cost is $4, i don’t determine to pay $2 (which is what cin >>totalPrice; is currently doing)


I’m required to have it for some reason and the teacher is saying " you didn’t print out the price
you just calculated it."

you are required to have this two lines:

    cout<< "What is the total price? ";
        cin >>totalPrice;


well, after you calculated the correct total price:

totalPrice = itemPrice * itemCount;

you never output it, i think that is what your teacher is saying


thank you for your help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.