int main()
{
cout << "How much money do you have?";
cin >> cash;
cout << "How much does the product cost?";
cin >> cost;
if (cash > cost)
cout << "Looks like you'll have enough money to pay for the product";
cout << "The amount of cash back will be " << (cash - cost) << endl;
if (cash == cost)
cout << "Looks like you just barely have enough money";
else
cout << "Looks like you'll need more money to buy the product";
cout << "The amount of money needed to buy the product is " << (cost - cash) << endl;
What is the problem?
And, What are Cash and Cost?
Edit: After looking at your previous posts, Let me say you need all the most basic tutorials. You may want to begin here: http://www.cplusplus.com/doc/tutorial/
Hi!
I'm a beginner in C++ as well but I think I can help you out with this assignment.
First thing you need to do is declare the variables before you call them.
Second thing is to format the if statements with the right syntax.
And the third thing would be to fix the formula for cash returned.
#include <iostream>
#include <iomanip> // add this directive so you can format the output
#include <cmath> // add this directive so you can use more arithmetic operators
usingnamespace std;
int main()
{
double cash, cost, change; // add a variable for cash returned, I called it "change"
cout << fixed << showpoint << setprecision(2); // This will display cash limited to two decimal places.
cout << "How much money do you have?" << endl; // Add end of line statement so that your display looks nice.
cin >> cash;
cout << "How much does the product cost?" << endl;
cin >> cost;
if (cash > cost) // Don't forget to add brackets with the if statement
{
change = cash - cost; // It's easier to make a variable for cash returned & the formula before your print statments
cout << "Looks like you'll have enough money to pay for the product." << endl;
cout << "The amount of cash back will be " << "$" << change << endl;
}
if (cash == cost)
{
change = cash - cost;
cout << "Looks like you just barely have enough money" << endl;
cout << "The amount of cash back will be " << "$" << change << endl;
}
if ( cash < cost)
{
change = abs (cash - cost); // abs takes the absolute value so you don't have a negative value for cash back.
cout << "Looks like you'll need more money to buy the product" << endl;
cout << "The amount of money needed to buy the product is " << "$" << change << endl;
}
return 0;
}