0

The output is not working in C++. The code is good.

#include <iostream> using namespace std; int main() { // your account's balance auto balance = 2452.4; // price for each notebook auto price = 259.99; // Task: calculate the number of notebooks you can afford and output it. // Hint: use an integer to store the result. int numberofbooksafford= balance/price; cout<<"Number of notebook you can afford :"<<numberofbooksafford<<endl; // Task: calculate the amount left over on your account after the purchase and output it on a new line. // Hint: calculate the total price of the purchase, then substract it from the balance. double totalPurchasePrice= numberofbooksafford* price; double amountLeftOver=balance-totalPurchasePrice; cout<< "Amount left over after the purchase"<<amountLeftOver<<endl; } I tried that output is still not working.

10th May 2024, 2:26 PM
Div Anand
Div Anand - avatar
6 Respostas
+ 4
Div Anand , Where is your attempt??
10th May 2024, 3:14 PM
Riya
Riya - avatar
+ 1
numberofbooksafford has type int while the result of the division result to double type. While you using type 'auto' for balance and price you can use auto for this as well
18th May 2024, 10:21 PM
john ds
john ds - avatar
0
The test is failing.
10th May 2024, 4:16 PM
Div Anand
Div Anand - avatar
0
most likely it's the extra closing brace at the end of the code
10th May 2024, 7:42 PM
Dawid Galuszka
Dawid Galuszka - avatar
0
Div Anand your code doesn't meet required criteria as you didn't followed instructions exactly: TASK 1: Calculate number of notebooks you can afford and output it. Expected output: (numberofbooksafford) Your output: Number of notebook you can afford: (numberofbooksafford) TASK2: Calculate the amount leftover... ... and output it on a new line. Expected output: (amountLeftOver) Your Output: Amount left over after the purchase (amountLeftOver)
11th May 2024, 9:55 AM
Dawid Galuszka
Dawid Galuszka - avatar