Can someone say what i have done wrongly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone say what i have done wrongly

#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 notebooks = balance/price; cout << notebooks <<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. cout << remainder=balance-(price*notebooks); }

3rd Apr 2023, 5:53 PM
Manith Samarasinghe
Manith Samarasinghe - avatar
2 Answers
+ 3
<remainder> is undefined, you should either define and assign its value then print it ... auto remainder = balance - ( price * notebooks ); cout << remainder; Or directly output the calculation result of <balance> subtracted by (<price> * <notebooks>) cout << ( balance - ( price * notebooks ) );
3rd Apr 2023, 6:18 PM
Ipang
+ 1
Oh thnx mate!!really helpful♥️
3rd Apr 2023, 6:20 PM
Manith Samarasinghe
Manith Samarasinghe - avatar