Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
the problem is " If number is greater than 1000 subtract 10% , if not subtract 5% "
Please Help its our Project in school
Thanks for those who will help .

What I have tried:

i didn't tried any codes yet cause i don't have any idea what code to use
Posted
Updated 26-Jan-17 22:16pm
Comments
Jon McKee 26-Jan-17 23:56pm    
Talk to your teacher or classmates. School is for teaching you how to learn and the basic skills you need to succeed. If you simply ask for answers you will learn neither of those skills.

Start here: Percentages. Then review basic conditional expressions in C#.
Member 12969710 27-Jan-17 0:30am    
Thank you sir.

Hey,first you have to know the fundamentals like variable,syntax,declaration,initialisation,loop,if....else format etc.
This is the logic of your requirement.
if(num > 1000) {
total = num-(num*0.10)
} else { total = num - (num*0.05}
 
Share this answer
 
Quote:
How do i...how to subtract a percentage from a number

As a programmer, you need to be at ease with mathematics. percentages is primary school level.
Quote:
subtract 10% from a number

translate to "number - 10% of number" => "number - (10 / 100) * number"
can also be seen as "number * (1 - 10 / 100 )" => "number * 0.9"

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
 
Share this answer
 
Hello:
Supose your original variable is x and the result that you want to get is the variable result, then you can use:
result=x*(x>1000?0.9?0.95)

Explanation:
The expresion (x>1000?0.9?0.95) has the following value:
  - 0.9 only if x>1000
  - 0.95 otherwise

So, result has teh following value:
  - x less a 10% of x only if x>1000
  - x less a 5% of x otherwise
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900