M
M
Maxim Rudnev2015-10-07 11:59:37
Programming
Maxim Rudnev, 2015-10-07 11:59:37

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

1 answer(s)
T
Tlito, 2015-10-07
@stigmt

1. you have an integer variable,
you need to organize a double type variable for the number 200.9
2. input check will make your program 2 times longer. so to begin with, limit yourself to a message like: Enter a number, separate tenths with a dot. And press Enter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question