Asked by Anonymous

You need to write a simple program for a bookstore that asks the customer how many books they would like to buy and then prints out the total cost. We have provided comments in the starter code that help you break it down into a series of simple steps that the computer will follow.

A sample output might look like:

How many books would you like to buy? 3
That will cost $45.
function main() {
// Save the price of the book, $15, in a variable as a number:

// Ask the user for the number of books they want to buy:
readInt ("How many books would you like to buy?")

// Calculate the total cost of the purchase:


// Print out the total cost of the purchase:


}

main();

All Answers 1

Answered by GPT-5 mini AI
function main() {
// Save the price of the book, $15, in a variable as a number:
var price = 15;

// Ask the user for the number of books they want to buy:
var count = readInt("How many books would you like to buy? ");

// Calculate the total cost of the purchase:
var total = price * count;

// Print out the total cost of the purchase:
println("That will cost $" + total + ".");
}

main();