Thread: Addition & multiply not working

  1. #1
    Registered User
    Join Date
    Jun 2016
    Posts
    6

    Addition & multiply not working

    Hai i wonder why my program cannot display the result of addition & multiply. Please advice me. I am using struct to run my programme. Here is the code
    Code:
    #include <stdio.h>
    struct employee
    {
        int ID;
        char name[15];
        int salary;
        int year;
        int increment,increment1;
    };
     
         
    int main()
     {
        struct employee record;
        int i,nu, salary, year;
        
        printf( "Enter number of employee: " );
        scanf("%d", &nu );
            printf("\n\n\n");
             for(i=0;i<nu;i++)
            {
        
            printf("Enter Employee number ID: ");
            scanf("%d", &record.ID);
            printf("Enter Employee Name: ");
            scanf("%s", &record.name[15]);
            printf("Enter Employee Salary: ");
            scanf("%d", &record.salary);
            printf("Enter Employee Service Year:");
            scanf("%d", &record.year);
            printf("\n\n");
            
            if( record.year > 10)
            {
            
              record.increment =  record.salary + (10 / 100);  
              printf("Congratulation your Latest Salary are 1 :%d", record.increment);
              printf("\n\n");
           }
            else
            {
                            
               record.increment1=( record.salary *  7/100) + record.salary ; 
                printf("Congratulation your Latest Salary are 2 :%d", record.increment1);
              printf("\n\n");
                       
           }
            
            }
        
        
            
            
            return 0;
    }
             
    
              
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,451
    Do you realize that when using integer math there are no fractions? 10/100 will yield zero.

    Jim

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Line 26 should be
    Code:
    …
            scanf("%14s", record.name);
    …
    Other have classes, we are class

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 01-09-2016, 06:53 AM
  2. Addition using only multiply and divide
    By abachler in forum Contests Board
    Replies: 26
    Last Post: 09-19-2007, 12:40 AM
  3. multiply by 7
    By agarwaga in forum C Programming
    Replies: 1
    Last Post: 05-22-2006, 02:19 PM
  4. Multiply it by 10 then Int to Hex
    By Mr. Acclude in forum C Programming
    Replies: 16
    Last Post: 09-23-2004, 08:15 PM
  5. multiply int..
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 04-14-2002, 08:23 AM

Tags for this Thread