Admin2 12 Report post Posted April 22, 2008 #include<stdio.h> #define RATE1 1.20 //Alternative lain kalau nak setkan nilai Rate #define RATE2 1.00 //Alternative lain kalau nak setkan nilai Rate float get_payment(float); void display(char[],float,float); main() { char name[100]; float weight,payment; int i; for(i=0; i<3;i++) { printf("--------------------------------------------\n"); printf(" ENTER LAUNDRY INFORMATION\n"); printf("--------------------------------------------\n"); fflush(stdin); printf("Enter name: "); gets(name); printf("Enter weight of laundry (kg): "); scanf("%f", &weight); printf("--------------------------------------------\n"); printf(" LAUNDRY PAYMENT INFORMATION\n"); printf("--------------------------------------------\n"); payment = get_payment(weight); display(name,weight,payment); } //For loop punya end } float get_payment(float weight) { float pay, ratePkg, rate; ratePkg = 0; if(weight>=0 && weight <=5) { ratePkg = 1.20; //Masalah sekrang ialah nak tulis code ni kat line ni const ratePkg = 1.20. tapi bila set constant kat sini tak boleh return value. } else if(weight>5) { ratePkg = 1.00; //Masalah sekrang ialah nak tulis code ni kat line ni const ratePkg = 1.00. tapi bila set constant kat sini tak boleh return value. } pay = weight * ratePkg; return pay; } void display(char name[],float weight,float payment) { printf("Customer Name: %s\n", name); printf("Laundry Weight (kg): %.2f\n", weight); printf("Payment : RM%.2f\n", payment); }kalau kita set kan const ratePkg = 1.20; atau const ratePkg = 1.20; kat bahagian function get_payment camne? sebab soalan dia suruh setkan constant dalam function get_payment cam kat bawah ni:Question 3You are required to create a complete program for UNIVERSITY LAUNDRY.• In main() function :o Get user input for name and amount of laundry kilogram.o Call function get_payment(...) and send amount of kilogram to calculate the payment for the service.o Call function display() to display the customer's name, kilogram and payment.• In function get_payment(...) :o Get the amount of kilogram from main() function.o Calculate the payment by referring to the following table.o The rate per kilogram must be DEFINE AS CONSTANT <----- NI LA DIA!!KILOGRAM RATE PER KILOGRAM0 – 5 RM 1.20> 5 RM 1.00• In function display() :o display the customer's name, kilogram and payment• This program must be repeated for three customers.• Use a for loop for this process. Quote Share this post Link to post Share on other sites
Paralys3r 0 Report post Posted April 24, 2008 bila dia cakapThe rate per kilogram must be DEFINE AS CONSTANTbiasanya dia maksudkan gunakan #define directive. So solution awak biasanya#define RATE1 1.20 #define RATE2 1.00 Quote Share this post Link to post Share on other sites
betik 11 Report post Posted April 27, 2008 float get_payment(float weight) { float pay, ratePkg, rate; ratePkg = 0; if(weight>=0 && weight <=5) { ratePkg = 1.20; //Masalah sekrang ialah nak tulis code ni kat line ni const ratePkg = 1.20. tapi bila set constant kat sini tak boleh return value. }yup...spt ckp Paralys3r....satu lg...ratePkg bkn x return value, tp kalu ko wat "const ratePkg = 1.20", sebenarnya, function tu x akan assign ratePkg tu kpd nilai 1.20 sbb ko declarekan dia sbg constant...dia akan tetap spt nilai sebelum ni (i.e: ratePkg = 0 yg ko da assign awal2 tu)... Quote Share this post Link to post Share on other sites
Admin2 12 Report post Posted May 7, 2008 thanx paralys3r dan betik. ye aku dah faham dah. so aku kena guna gak la #define ye. ookk Quote Share this post Link to post Share on other sites
otai_g 3 Report post Posted August 13, 2008 (edited) x payah guna define pun blh.ni cth yg aku buat #include <iostream> using namespace std; //#define RATE1 1.20 //Alternative lain kalau nak setkan nilai Rate //#define RATE2 1.00 //Alternative lain kalau nak setkan nilai Rate double get_payment(float); void display(char*,float,float); void main() { char name[100]; float weight, payment; int i; for(i=0; i<3; i++) { cout<<"--------------------------------------------"<<endl; cout<<" ENTER LAUNDRY INFORMATION "<<endl; cout<<"--------------------------------------------"<<endl; cout<<"Enter name : "; cin>>name; cout<<"Enter weight of laundry (kg) : "; cin>>weight; cout<<"--------------------------------------------"<<endl; cout<<" LAUNDRY PAYMENT INFORMATION "<<endl; cout<<"--------------------------------------------"<<endl; get_payment(weight); payment = get_payment(weight); display(name,weight,payment); } //For loop punya end } //main punya end double get_payment(float weight) { float pay = 0; const double ratePkg_1 = 1.2; const double ratePkg_2 = 1; if (weight>=0 && weight <=5) pay = weight * ratePkg_1; else pay = 6 + ( (weight-5) * ratePkg_2 ); return pay; } // end get_payment function void display(char name[], float weight, float payment) { cout<<"Customer Name : "<<name<<endl; cout<<"Laundry Weight (kg) : "<<weight<<endl; cout<<"Payment : RM "<<payment<<endl; } Edited August 13, 2008 by otai_g Quote Share this post Link to post Share on other sites