Wazee wa programing, nisaidieni hili swali

Wazee wa programing, nisaidieni hili swali

Paa

JF-Expert Member
Joined
Jun 12, 2015
Posts
1,462
Reaction score
2,940
Write a C program which computes gross salary of an employee. Let your program input the rate of pay, hours worked, and service record in years. When the service record is greater than 10 years an allowance of 15% of gross salary is given.
Mimi nimefanya kama inavyoonekana hapa chini lakini nimekwama kidogo
b881b67287ce66f53e819e0dac75e33d.jpg
 
ngoja waje
Sent from my galaxy jamiiforums app
 
Kwenye code yako mstari wa 18 "else(years>10)", else haina condition, ukitaka kutumia condition tumia "else if(years>10)"
 
Nitakujibu nikikaa kwenye computer maana siwezi code kabisa kwa kutumia simu. Naona unatumia tablet, huna mashine mkuu?

Alafu elezea swali lako vizuri wakati huo, kwa nini mtu anaingiza hours worked? Je kuna pay per hour? Maana hapo umesema rate of pay, rate of pay per what? Rate siku zote hua ni something over something, labda 10shs/hour.

Alafu bug yako hapo tatizo ni semicolon, huoni imekuandikia kabisa?
 
[HASHTAG]#include[/HASHTAG]<stdio.h> int main(){ int x,y; printf("Enter value for x :"); scanf("%d",&x); printf("Enter value for y :"); scanf("%d",&y); if ( x > y ){ printf("X is large number - %d\n",x); } else{ printf("Y is large number - %d\n",y); } return 0; }
 
kwenye else ( years>10), toa iyo (years>10) ibaki ELSE tupu!
 
Kwenye code yako mstari wa 18 "else(years>10)", else haina condition, ukitaka kutumia condition tumia "else if(years>10)"
Nimejaribu imegoma
 
Nitakujibu nikikaa kwenye computer maana siwezi code kabisa kwa kutumia simu. Naona unatumia tablet, huna mashine mkuu?

Alafu elezea swali lako vizuri wakati huo, kwa nini mtu anaingiza hours worked? Je kuna pay per hour? Maana hapo umesema rate of pay, rate of pay per what? Rate siku zote hua ni something over something, labda 10shs/hour.

Alafu bug yako hapo tatizo ni semicolon, huoni imekuandikia kabisa?
Sina mashine iliibiwa.
Mr. Graph hapo nimeliweka swali kama lilivyo, sijabadilisha chochote. Pia hata mimi sikuona mantiki ya ya kuweka hours worked kwakuwa haina kazi kwenye computation.
Sijajua bado kwanini inahitajika, ndio maana nikaja humu kuomba wajuvi mnosaidie
 
Mimi sina ujuzi wa C programming, ila nimejaribu kujibu kwa Java...

Code:
package com.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        double grossSalary, payRate,extraSalary;

        byte hoursWorked, serviceRecord;

        Scanner userInput = new Scanner(System.in);
       
//        prompt user to enter the payrate
        System.out.println("Enter your payrate (Tsh per hour):");
        payRate = userInput.nextByte();
       
        //        prompt user to enter the hours
        System.out.println("Enter number of hours you worked:");
        hoursWorked = userInput.nextByte();
       
        //        prompt user to enter service record
        System.out.println("Enter your service record in years:");
        serviceRecord = userInput.nextByte();


        //check if service record is less than 10

        if (serviceRecord <= 10) {
            grossSalary = payRate * hoursWorked;
            System.out.println("Your gross salary is:" + grossSalary);
        }
       
        //check if service record is greater than 10

        else {
            grossSalary = (payRate * hoursWorked);
           
//            extraSalary is the amount of money worker receive when his service record is >10
            extraSalary = grossSalary + 0.15 * grossSalary;
            System.out.println("Your gross salary is:" + extraSalary);

        }

    }
}
 
Nitakujibu nikikaa kwenye computer maana siwezi code kabisa kwa kutumia simu. Naona unatumia tablet, huna mashine mkuu?

Alafu elezea swali lako vizuri wakati huo, kwa nini mtu anaingiza hours worked? Je kuna pay per hour? Maana hapo umesema rate of pay, rate of pay per what? Rate siku zote hua ni something over something, labda 10shs/hour.

Alafu bug yako hapo tatizo ni semicolon, huoni imekuandikia kabisa?
Nilivyoelewa swali ni kwamba user anaweka payrate yake ambayo inakua per hour (say 2000Tsh/hour) then ataweka tena idadi ya masaa aliyofanya kazi, mpaka hapa ukizidisha payrate na idadi ya masaa, hour ina cancel unabakiwa na amount of salary in Tsh! (2000Tsh/hour*8hours)!

Sasa kama amezidi service record imezidi 10years utafanya tena upate total salary + 15% ya gross salary!
 
Write a C program which computes gross salary of an employee. Let your program input the rate of pay, hours worked, and service record in years. When the service record is greater than 10 years an allowance of 15% of gross salary is given.
Mimi nimefanya kama inavyoonekana hapa chini lakini nimekwama kidogo.

Input inakwambia iwe rate, hours na years. Hiyo basic umeitoa wapi? Haipo kwenye requirements.

Salary ni (hours * rate)
kama amefanya kazi more than 10 years unaongezea asilimia 15 ya salary,
i.e salary + (salary * 0.15)

Pia float hazifai kuhifadhi hela kwa vile hazina precision ya kutosha although kwa vile hii ni homework ya darasani unaweza ukaruhusiwa.

Unaweza kuona hapa mifano Floating point inaccuracy examples

Na hapa kwa maelezo ni kwanini float haifai unapohitaji precision The Floating-Point Guide - What Every Programmer Should Know About Floating-Point Arithmetic
 
Nashukuruni wote kwa michango yenu nimeshapata solution
 
mkuu, rudi pitia ' placeholders'
juu ume declare service_record as 'int'
alafu line ya 11 , umeiscan as 'float'

badili iyo %f kua %d, kwenye line ya 11, na ubishi uache maana wewe ndio unaitaji msaada mkuu!
 
Back
Top Bottom