Answer the question
In order to leave comments, you need to log in
Division by float?
On the example of the problem:
1 cucumber = 200.50 rubles, we
pay 200 rubles and get the result: you can buy 1 cucumber, although the output value is clearly less than one. Help with division
https://yadi.sk/i/sMVv1V3DjZwU4 - screenshot with cmd and compiler
Code:
#include
#include
using std::cout;
using std::cin;
using std::endl;
int main()
{
setlocale(LC_ALL, "Russian");
int a;
cout << "Enter amount" << endl;
cin >> a;
const int b=200.9;
int c = a % b;
int v = (double)a / (double)b;
if (v >= 1.0)
cout << "Purchase possible, you will receive: "<< v <<" item\n" << "Your change:" << c << endl;
else
cout << "You don't have enough funds" << endl;
_getch();
return 0;
}
2) The second question after: how to make it so that when you enter letters, not numbers, a message is displayed?
For example: "Error. Please enter numbers"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question