Noobie Code Help

This is a discussion on Noobie Code Help within the C Programming forums, part of the General Programming Boards category; Hello all this is my first post, I know i'm not supposed to just ask for answers so i given ...

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    3

    Noobie Code Help

    Hello all this is my first post, I know i'm not supposed to just ask for answers so i given it a solid go and I'm stumped, i don't know all that much so i'm sure its a few little things but any help would be great. Here's what i'm supposed to be doing and what I've got.

    Write a program in C to calculate the insurance premium for a building (house) insurance. The premium depends on the amount insured and also has a processing charge of $50. Customers are charged 0.3% of the amount insured, where the insured amount is less than $100,000, and 0.25% for other amounts. Customers that have zero claims receive a 10% reduction in their total premium as a no claim bonus. The amount insured is always a multiple of $1000.

    Code:
    #include <stdio.h>
    
    
    int main()
    {
       int amountinsured, numberofclaims, premium, noclaimbonus;
       printf("Input amount insured:");
       scanf(" %d", &amountinsured);
       printf("Input number of claims:");
       scanf(" %d", &numberofclaims);
    
    
       if (amountinsured<100000)
       {
          premium=(amountinsured*.003)+50;
       }
       else
       {
          premium=(amountinsured*.0025)+50;
       }
    
    
       printf("Amount Insured:%d\n",amountinsured);
       printf("Number of Claims:%d\n",numberofclaims);
       if (numberofclaims = 0)
       {
          noclaimbonus = premium*.1;
          premium = premium - noclaimbonus;
          printf("No claim bonus:%d\n",noclaimbonus);
       }
       printf("Premium:%d\n",premium);
       return 0;
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    if (numberofclaims = 0)
    This is asignement. Use ==

    Kurt

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    3
    Quote Originally Posted by ZuK View Post
    Code:
    if (numberofclaims = 0)
    This is asignement. Use ==

    Kurt
    Well that's one thing i missed, problem is it doesn't work properly before it gets to that, I'm getting much to high a number for the premium and i don't know why.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,787
    premium is an int, but you appear you want a floating point variable, e.g., of double type.
    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

  5. #5
    Registered User
    Join Date
    Jun 2013
    Posts
    3
    Quote Originally Posted by laserlight View Post
    premium is an int, but you appear you want a floating point variable, e.g., of double type.
    Yeah that was it, thank you so much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Very noobie question!
    By ewandougie in forum C++ Programming
    Replies: 5
    Last Post: 01-10-2010, 11:45 AM
  2. Some help for a Noobie!
    By barryr in forum C Programming
    Replies: 22
    Last Post: 11-29-2009, 07:59 AM
  3. Noobie Little Help Please
    By Mike1982 in forum C Programming
    Replies: 2
    Last Post: 09-18-2007, 10:34 PM
  4. help me im a C++ noobie!!!
    By fatso in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2002, 10:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21