+ 3
i dont understand why this doesn't work
#include <iostream> using namespace std; int main() { // your account's balance auto balance = 2452.4; // price for each notebook auto price = 259.99; auto notebooks = balance / price; auto rimasto = balance - (macbooks * price); cout << notebooks; cout << rimasto; // Task: calculate the number of notebooks you can afford and output it. // Hint: use an integer to store the result. // 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. }
11 ответов
+ 7
… have you changed the line suggested?
#include <iostream>
using namespace std;
int main() {
auto balance = 2452.4;
auto price = 259.99;
auto notebooks = balance / price;
auto rimasto = balance - (notebooks * price);
cout << notebooks;
cout << rimasto;
}
This is your code (comments removed). Where you had macbooks, changed to notebooks works fine for me. Outputs 9.432670
+ 4
I had the same answer with different variables as DavX but it still failed on me. I had to do it the exact way the "See Solution" had it or it didn't work. What I was entering was:
int main() {
auto balance = 2452.4;
auto price = 259.99
auto afford = balance /price;
auto left = balance - (afford *price);
cout << afford << endl;
cout << left;
}
What gave me the green light for good code was:
int main() {
auto balance = 2452.4;
auto price = 259.99;
int total = balance / price;
cout << total << endl;
cout << balance - (total *price);
}
+ 3
You haven’t declared or initialized the variable ‘macbooks’…
You cannot multiply an unknown 👍
+ 2
thanks
+ 2
add endline in notebooks output
#include <iostream>
using namespace std;
int main() {
// your account's balance
auto balance = 2452.4;
// price for each notebook
auto price = 259.99;
int notebooks = balance/price;
auto price2= balance-(notebooks*price);
cout << notebooks<<endl;
cout << price2;
}
+ 1
it still doesn't work, i checked the comments and it seems that im not the only one with this problem
+ 1
Try to end this code with return 0;
+ 1
The task says you should output the last one on a new line... use <<endl;
0
thnx justin cross.
i've tried is some many times but they want you to do the math in the print.thnx!
0
#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.
cout << "You can afford " << int(balance / price) << " 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 << "The Amount you have left over in your account is quot; << balance - ((int(balance/price)) * price) << " Dollars" << endl;
return 0;
}
//Why does this not work I have ran it through a compiler and everything works well! I tried assigning variables prior but nothing like that worked
0
// this is right answer
#include <iostream>
using namespace std;
int main() {
auto balance = 2452.4;
auto price = 259.99;
int total = balance / price;
cout << total << endl;
cout << balance - (total *price);
}
// this is wrong answer 💀🙏🏼
#include <iostream>
using namespace std;
int main() {
// your account's balance
auto balance = 2452.4;
// price for each notebook
auto price = 259.99;
// affordable number of notebooks
int notebooks = balance / price;
// purchased amount
int purchased = price * notebooks;
// amount left in my balance after purchase
int amount = balance - purchased;
// Amount output
cout << notebooks << endl;
cout << amount;
// Task: calculate the number of notebooks you can afford and output it.
// 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.
// Hint: use an integer to store the result.
}
// no hate to this app cuz its free 💀🙏🏼 and teaching me