Thread: Need a little help!!

  1. #1
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20

    Lightbulb Need a little help!!

    Hi, i'm doing my assignment and i dont know this particular coding.

    Well to sum up my question....

    i need to know what is the code to find the balance of a number after it has been deducted to 10 percent.(this is only a small part from the whole assignment)

    Anybody would like to tell me?

    I need a full code if you don't mind.

    Thanks.

    oh and i need it like ASAP!!
    Last edited by Doink; 10-05-2007 at 09:14 AM. Reason: misunderstanding

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You need to read our homework policy ASAP!!
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    I have read it and my question is not against the policy.

    My question was about one particular code. And the code i'm asking is not for the entire assignment. it's just apart of it. I have done the other code(assignment's) except for that . So that's why i'm asking.

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    The code part is irrelevant, as it almost exactly equivalent to the math of it.

    How would you remove 10 % from a number?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I have read it and my question is not against the policy.
    I note that you wrote: "I need a full code if you don't mind."

    Anyway... if I am reading it correctly, it is so trivial that the bulk of the code is a one liner. If you have a number x, what is ten percent of x, expressed as a fraction? What about expressing it in decimal?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    Quote Originally Posted by IceDane View Post
    The code part is irrelevant, as it almost exactly equivalent to the math of it.

    How would you remove 10 % from a number?
    ok let say a person's salary is $2345.

    my program identifies whether the salary needs to be deducted 10 percent or not.

    if it needs to be deducted,I just need to know the salary balance.

    that's all.

    I have tried to put this code into my coding but it wont show up anything on the black screen after the data has been entered.

    Code:
    total_salary=salary-salary*0.10

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah, now we're seeing something. Okay, that looks like it will work. Perhaps you carelessly forgot to print total_salary, hence "it wont show up anything"? It would be good to provide the smallest and simplest (compilable) program that demonstrates the problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sorry, can't help but post my one-liner:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() { char buf[20]; int n; printf("%d\n",(n = strtol(fgets(buf, sizeof(buf), stdin)?buf:"0", 0, 10))?n -= n / 10:0); return 0;}

    This is a piece of code to subtract 10% of a number, not the full specs of your code. [And I would suggest that you DON'T use this code as part of your homework - it is not for homework level use [in fact, I wouldn't suggest using this sort of thing anywhere, except when the goal is to make one-liner code].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    Quote Originally Posted by laserlight View Post
    Ah, now we're seeing something. Okay, that looks like it will work. Perhaps you carelessly forgot to print total_salary, hence "it wont show up anything"? It would be good to provide the smallest and simplest (compilable) program that demonstrates the problem.
    how should i do that?

    i'm kind of new to C.

    how do i print the total_salary


  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i'm kind of new to C.

    how do i print the total_salary
    You have probably been taught how to use printf(), methinks. Use that.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    Quote Originally Posted by laserlight View Post
    You have probably been taught how to use printf(), methinks. Use that.

    ok, take a look at this....

    Code:
    total_salary=salary-salary*0.10;
    printf("your new salary balance is%f",salary);
    is that correct? or do i need to put another printf?

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    printf seems about right, but perhaps you should consider WHAT you are printing in that printf.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    Quote Originally Posted by matsp View Post
    printf seems about right, but perhaps you should consider WHAT you are printing in that printf.

    --
    Mats
    err come again?

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You are printing salary instead of total_salary.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    Quote Originally Posted by laserlight View Post
    You are printing salary instead of total_salary.
    it would be helpful if you show me the right printf code instead of making me confuse, don't you think?

Popular pages Recent additions subscribe to a feed