percentage program

Hi,I'm very new to this language, I'm in the midst of doing an assignment for my college and I'm stuck with this lines of codes.

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
float n;

cout << "Enter total sale value";
cin >> n;
n = ( n <= 1000000 * 0.2);

if ( n <= 1000000 * 0.2);

cout <<"The agents commission is : "<< (n <= 1000000 * 0.2);

}

The program is supposed to calculate the percentage of less then or equal to one million and is keeps giving me the result = 1.

Please somebody help me.

Thanks for your time.
Last edited on
I don't understand what you're trying to do... You want to get n as a percentage of everything <= 1,000,000?

The reason it is giving you 1 every time is because in n = (n <= 1000000 * 0.2); n <= (1000000 * 0.2) is evaluated. If n is indeed less than or equal to 1,000,000 * 0.2 (200,000) then n is set to 1. Otherwise it is set to 0.

So if you entered 200,001 then you would get 0.

As I say I don't understand what you're trying to get as a result of your program, so explain and I will help more.
Thanks for your reply. What I'm trying to get is a 2% commission if the sale is less than or equal to one million.
The program is supposed to calculate 2% 5% and 7% commission on a given sale value, from 1 million to 2.5 million.
What the program is supposed to do is: The user inputs the total sale value, and the program should calculate the percentage of the commission to the sales person.

I do understand what you mean, but I'm still stuck on how to make the program calculate the percentage.

Thanks again.
Last edited on
Topic archived. No new replies allowed.