0
I’m trying to get the program to calculate the discount value of a certain value entered by the user;
#include <iostream>
#include <stdio.h>
#include <locale.h>
using namespace std;
int main()
{
float number1, number2, desconto;
cout << "Digite o valor de compra do seu produto R$ ";
cin >> number1;
desconto = number1 * (30 / 100);
number2 = number1 - desconto;
cout << "O produto custa R$ " << number2 << " reais com 10% de desconto.";
system("pause");
return 0;
}
I’m seeing a problem, but it would help if you described what’s happening differently than expected, and what your difficulty is.
– Andre
for example: if I enter with the value of 120 the program does not return me the correct value that would be the discount of 30%, returns me the same 120
– glaubermlira
So the values
30
and100
are integers, and the result of dividing whole numbers is an integer, that is, it will be0
. If you want the result to be0.3
, should do30.0 / 100.0
.– Andre
Thanks bro, it was just that, it worked out great!!!
– glaubermlira