MatchMaker 0 Report post Posted March 24, 2010 Loop tu run 4 kali. 1 + 4 sebab cin yang 1st tu luar loop. sebab tu nampak cam 5. kalau aku, aku akan buat camni. [code]#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int j, score[5], max = 0; cout << "enter 5 scores ...\n"; for (j = 0; j < 5; j++) { cout << "score number " << j + 1 << " : "; cin >> score[j]; if (score[j] > max ) max = score[j]; } cout << "\n\nThe highest score is : " << max << endl; system("PAUSE"); return EXIT_SUCCESS; }[/code] defaultkan dulu max kepada 0. lagi satu, kalau nak lagi cantik, j ngan array tu buat dynamic. so suruh user yang masukkan berapa byk scores yg dia nak. jadi takdela fix 5 je untuk array. Quote Share this post Link to post Share on other sites
hamster91 0 Report post Posted March 30, 2010 #include <iostream.h> void main () { int i, angka [6] = {1,2,3,4,5,6} ; for ( i=0 ; i<6 ; i++ ) { angka[i]=i+1 ; cout << "masukkan integer : " <<angka[i]<<endl ; } } macammane nk jadikan output coding ny dalam reversed order?? output yang ak dapat sebelum reversed order.. masukkan integer :1 masukkan integer :2 masukkan integer :3 masukkan integer :4 masukkan integer :5 masukkan integer :6 Quote Share this post Link to post Share on other sites
ahaksz! 44 Report post Posted March 30, 2010 reverse counter dari 5 ke 0.. [code] for ( i=5 ; i != -1 ; i-- ){ cout<<"Reversed: "<<angka[i]<<endl; } [/code] EDIT: tapi yang pelik sikit dekat sini.. [font="Courier New"]int i, [b]angka [6] = {1,2,3,4,5,6}[/b] ; [b]angka[i]=i+1[/b] ;[/font] first tu dah initialize array [font="Courier New"][b]angka[/b][/font] tu apa element dalam dia.. then dalam loop tu buat yang sama..[s]array size pun rasa salah tu.. kalo ikot [font="Courier New"][b]angka [6][/b][/font], element dalam angka mesti ada 7 sebab index start dari 0 sampai 6..[/s] Quote Share this post Link to post Share on other sites
hamster91 0 Report post Posted March 30, 2010 [quote name='hamster91' date='30 March 2010 - 05:02 PM' timestamp='1269939762' post='1023722'] #include <iostream.h> void main () { int i, angka [6] = {1,2,3,4,5,6} ; for ( i=0 ; i<6 ; i++ ) { angka[i]=i+1 ; cout << "masukkan integer : " <<angka[i]<<endl ; } } macammane nk jadikan output coding ny dalam reversed order?? output yang ak dapat sebelum reversed order.. masukkan integer :1 masukkan integer :2 masukkan integer :3 masukkan integer :4 masukkan integer :5 masukkan integer :6 [/quote] sy da dpat coding da tok reversed order 2..wat sendiri td..: #include <iostream.h> void main () { int i,angka [6] = {1,2,3,4,5,6} ; for ( i=0 ; i<6 ; i++ ) { angka[i]=i+1 ; cout << "masukkan integer : " <<angka[i]<<endl ; } for ( i=0 ; i<6 ; i++ ) { angka[i]=6-i ; cout <<"susunannya adalah :" <<angka[i]<<endl ; } } Quote Share this post Link to post Share on other sites
hamster91 0 Report post Posted March 30, 2010 tp sy buat coding 2..betul mcm ape output dy dkehendaki.. Quote Share this post Link to post Share on other sites
ahaksz! 44 Report post Posted March 30, 2010 [quote name='hamster91' date='30 March 2010 - 08:57 PM' timestamp='1269953865' post='1023775'] tp sy buat coding 2..betul mcm ape output dy dkehendaki.. [/quote] [s]yap memang betul tapi cuba comment dulu line ni [font="Courier New"][b]angka[i]=6-i ; angka[i]=i+1 ;[/b][/font] and then run..[/s] woot.. maap.. salah paham dengan coding.. memang betul dah coding bro hamster91..cuma rasanya value yang di declare dekat array [b]angka [6] = {1,2,3,4,5,6}[/b] tak pakai pun.. Quote Share this post Link to post Share on other sites
MatchMaker 0 Report post Posted March 31, 2010 Macam kata ahaksz28, nampaknya takde guna value assignment kat angka tu. Quote Share this post Link to post Share on other sites
hamster91 0 Report post Posted April 6, 2010 #include <iostream.h> #define discount 30 #define per_year 12 int main() { char customer[100]; char kad_pengenalan[30]; char code[50] ; char penj1[100]; char penj2[100] ; char alamat_rmh[200]; char lesen_kenderaan[20],model_kenderaan[50],plat_kenderaan[50]; int normal_price,salary,year,month; int cash,instalment,interest; cout<<"please enter your name:" <<endl; cin.getline (customer,100) ; cout<<"please enter your identity card number:"<<endl; cin.getline (kad_pengenalan,30); cout<<"please enter your house address:"<<endl; cin.getline(alamat_rmh,200); cout<<"please enter your first guarantee name:" <<endl; cin.getline(penj1,100); cout<<"please enter your second guarantee name:" <<endl; cin.getline(penj2,100); cout<<"please enter your vehicle license:"<<endl; cin.getline(lesen_kenderaan,20); cout<<"please enter your vehicle model:"<<endl; cin.getline(model_kenderaan,50); cout<<"please enter your vehicle plat number:"<<endl; cin.getline(plat_kenderaan,50); cout<<"please enter the code of the payment (C=cash,I=instalment):"<<endl; cin.getline(code,50); cout<<"enter period of year for instalment payment:"<<endl; cin>>year; cout<<"please enter your month salary:RM"<<endl; cin>>salary; cout<<"please enter your price of vehicle:RM"<<endl; cin>>normal_price; switch (code[50]){ case 'C': cash=normal_price-(discount/100)*normal_price; break; case 'I': month=year*per_year; instalment=normal_price*month; interest=instalment+30; break; default: cout<<"the code you have entered does not valid"<<endl; cout<<"the net price is:RM"<<cash<<endl; cout<<"the instalment price is:RM"<<instalment<<endl; } return 0; } ape yang salah pada coding sy ny?? sy nk run program xbole la... mslh kat formula ke???? Quote Share this post Link to post Share on other sites
ahaksz! 44 Report post Posted April 6, 2010 err.. nape pakai char ek.. tak pakai String? Quote Share this post Link to post Share on other sites
hamster91 0 Report post Posted April 7, 2010 haa???string?? erm..sy blaja c++ xgune string pn..char je..formula untuk case 'I' tu betul ke?? sy wat mini projek untuk system pembelian kereta.. Quote Share this post Link to post Share on other sites
ahaksz! 44 Report post Posted April 7, 2010 hmmm.. kenapa tak declare variable [font="Courier New"][b]code[/b][/font] macam biasa je.. no need [font="Courier New"][b][50][/b][/font].. so just declare jadi [b][font="Courier New"]char code;[/font][/b] [quote]switch ([b][font="Courier New"]code[/font][/b]){ case 'C': cash=[b][font="Courier New"]normal_price-(0.3*normal_price);[/font][/b] break; case 'I': month=year*per_year; instalment=normal_price*month; interest=instalment+30; break; [font="Courier New"][b]default: cout<<"the code you have entered does not valid"<<endl; }[/b][/font] cout<<"the net price is:RM"<<cash<<endl; cout<<"the instalment price is:RM"<<instalment<<endl;[/quote] default tu patut sampai [b][font="Courier New"]cout<<"the code you have entered does not valid"<<endl;[/font][/b] je.. kalo tak output yang 2 lagi kat bawah tu takkan display unless user salah tekan huruf selain C or I.. one more thing kalo boleh tambah untuk lowercase c dengan i..mean even user tekan lowercase c still program tu accept input sebagai Cash.. contoh: [quote] case 'C': [b][font="Courier New"]case 'c':[/font][/b] cash=normal_price-(0.3*normal_price); break;[/quote] err..actually nanti memang akan calculate installment juga ke kalo dah pilih Cash? if not better letak [b][font="Courier New"]cout[/font][/b] yang last tu dalam case memasing.. kalo tak even pilih Cash installment punya output still keluar.. contoh: [quote] case 'C': [b][font="Courier New"]case 'c':[/font][/b] cash=normal_price-(0.3*normal_price); [b][font="Courier New"]cout<<"the net price is:RM"<<cash<<endl;[/font][/b] break;[/quote] and lastly kalo boleh make sure each variable yang di declare initialize kan value dia.. macam normal_price, salary, year, month tu equal to 0.. kalo tak macam sekarang ni bila last nanti dia akan keluar nombor pelik2 time result dia kalo condition salah.. p/s sorry kalo solution ni lari dari soalan or skop sistem yang nak dibuat.. Quote Share this post Link to post Share on other sites
hamster91 0 Report post Posted April 27, 2010 [quote name='hamster91' date='06 April 2010 - 10:47 PM' timestamp='1270565253' post='1024747'] #include <iostream.h> #define discount 30 #define per_year 12 int main() { char customer[100]; char kad_pengenalan[30]; char code[50] ; char penj1[100]; char penj2[100] ; char alamat_rmh[200]; char lesen_kenderaan[20],model_kenderaan[50],plat_kenderaan[50]; int normal_price,salary,year,month; int cash,instalment,interest; cout<<"please enter your name:" <<endl; cin.getline (customer,100) ; cout<<"please enter your identity card number:"<<endl; cin.getline (kad_pengenalan,30); cout<<"please enter your house address:"<<endl; cin.getline(alamat_rmh,200); cout<<"please enter your first guarantee name:" <<endl; cin.getline(penj1,100); cout<<"please enter your second guarantee name:" <<endl; cin.getline(penj2,100); cout<<"please enter your vehicle license:"<<endl; cin.getline(lesen_kenderaan,20); cout<<"please enter your vehicle model:"<<endl; cin.getline(model_kenderaan,50); cout<<"please enter your vehicle plat number:"<<endl; cin.getline(plat_kenderaan,50); cout<<"please enter the code of the payment (C=cash,I=instalment):"<<endl; cin.getline(code,50); cout<<"enter period of year for instalment payment:"<<endl; cin>>year; cout<<"please enter your month salary:RM"<<endl; cin>>salary; cout<<"please enter your price of vehicle:RM"<<endl; cin>>normal_price; switch (code[50]){ case 'C': cash=normal_price-(discount/100)*normal_price; break; case 'I': month=year*per_year; instalment=normal_price*month; interest=instalment+30; break; default: cout<<"the code you have entered does not valid"<<endl; cout<<"the net price is:RM"<<cash<<endl; cout<<"the instalment price is:RM"<<instalment<<endl; } return 0; } ape yang salah pada coding sy ny?? sy nk run program xbole la... mslh kat formula ke???? [/quote] boleh x sape2 tulung pelbagaikn lg fungsi progrm ny slaen dpd bole kire cara bayaran pmbelian kete je.. sebb lect kate kalo g byk fungsi g bgus.. ;D soe lme x msk forum..bz ngn mcm2 mini projek..huhuhu Quote Share this post Link to post Share on other sites