iana 0 Report post Posted September 5, 2005 kenapa looping ni tak jadi?tak faham la..#include<iostream>using std::cout;using std::cin;int func_play();int func_guess();int num_1, num_2;void main(){ cout<<"I have a number between 1 and 1000 \n"; cout<<"Can you guess my number? \n"; cout<<"Your first guess:"; cin>>num_1;// num_2 = 28; func_guess();}int func_guess(){ num_2 = 28; while(num_1>=1&&num_1<=1000){ if(num_1==num_2) { int choice; cout<<"Excellent! You guess the number!\n"; cout<<"Would you like to play again?\n\n"; cout<<"1. Play again\n"; cout<<"2. Out of the game\n"; cout<<"Your choice is: "; cin>>choice; if(choice==1) { func_play(); } if(choice==2) { cout<<"You're out of the game!\n"; } } else if(num_1<num_2) { cout<<"Too low. Try again\n"; func_play(); } else { cout<<"Too high. Try again\n"; func_play(); } } return 0;}int func_play(){ int num_1; cout<<"Enter your next guess: "; cin>>num_1; func_guess(); return 0;} Quote Share this post Link to post Share on other sites
da^hype 0 Report post Posted September 5, 2005 (edited) http://www.hirc.org/submit/view.php?id=122srry, sini dah kul 3 pagi. tapi aku ada buat code mcm tu. i'll take a look at u're code tomorrow (ngantuk sgt now). hope that helps.edit: actually..while(num_1>=1&&num_1<=1000)try and change it to.while (num_1 != num_2)also u're not passing a value into func_guess(); Edited September 5, 2005 by da^hype Quote Share this post Link to post Share on other sites
da^hype 0 Report post Posted September 5, 2005 (edited) oohh well made some tea. and fixed u're code. #include <iostream> using namespace std; void func_play(void); int func_guess(); int num_1, num_2; int choice; int func_guess(int num1) { num_2 = 28; while(num1 != num_2) { if(num1<num_2) { cout<<"Too low. Try again\n"; func_play(); } else { cout<<"Too high. Try again\n"; func_play(); } } cout<<"Excellent! You guess the number!\n"; cout<<"Would you like to play again?\n\n"; cout<<"1. Play again\n"; cout<<"2. Out of the game\n"; cout<<"Your choice is: "; cin>>choice; if(choice==1) func_play(); if(choice==2) { cout<<"You're out of the game!\n"; return 0; } return 0; } void func_play(void) { cout<<"Enter your next guess: "; cin>>num_1; func_guess(num_1); } int main() { cout<<"I have a number between 1 and 1000 \n"; cout<<"Can you guess my number? \n"; cout<<"Your first guess:"; cin>>num_1; func_guess(num_1); return 0; } u have problems with u're function not getting values. and logic error in func_guess(). func_play() tu takyah return value, pakai void. everything else looks great.read up on functions http://www.cplusplus.com/doc/tutorial/tut2-2.htmlgood luck Edited September 5, 2005 by da^hype Quote Share this post Link to post Share on other sites
smily 0 Report post Posted September 7, 2005 coding untuk problem yang sama tapi aku tambah random number generator dan detect brapa kali user try untuk guess number tu. #include <iostream> #include <ctime> using namespace std; void play(void); void play_again(int, int); void check_value(int , int); int main(void) { play(); return 0; } void play() { int num1, num2; srand((unsigned int) time(NULL)); // random seed num2 = rand() % 1000 + 1; // nombor random [julat 1 -> 1000] cout << endl; cout << "I have a number between 1 and 1000 \n"; cout << "Can you guess my number? \n"; cout << "Your first guess: "; cin >> num1; check_value(num1, num2); play_again(num1, num2); } void play_again(int num1, int num2) { int counter = 0; // store brapa kali user try int choice = 1; while(num1 != num2) { cout << "Enter your next guess: "; cin >> num1; check_value(num1, num2); counter++; } cout << endl; cout << "Excellent! You guess the number in " << counter + 1 << " tries!\n"; cout << "Would you like to play again?\n\n"; cout << "1. Play again\n"; cout << "2. Out of the game\n"; cout << "Your choice is: "; cin >> choice; if(choice == 1) play(); if(choice == 2) { cout << endl; cout << "You're out of the game!\n"; } } void check_value(int num1, int num2) { if(num1 < num2) cout << "Too low. Try again\n"; if(num1 > num2) cout << "Too high. Try again\n"; } sila beri tunjuk ajar... Quote Share this post Link to post Share on other sites
niM_skARm 0 Report post Posted October 31, 2005 ni aku lak nk mintak tlg...cam ner nak membangunkan aturcara penghimpun M68K m'gunakan c++?tau tak..? tak pun kat mana aku leh dapatkan contoh dier?? Quote Share this post Link to post Share on other sites
ahz 0 Report post Posted February 7, 2006 saya nak tanya.macam mana nak paprkan nombor-nombor perdana kurang daripada 100 menggunakan c++ Quote Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted February 8, 2006 (edited) ni aku lak nk mintak tlg...cam ner nak membangunkan aturcara penghimpun M68K m'gunakan c++?tau tak..? tak pun kat mana aku leh dapatkan contoh dier??←http://www.monroeccc.edu/ckelly/EASy68K.htm dgn menggunakan http://www.google.com/search?hl=en&q=68000+Assemblerkesimpulannya: alaaahai Edited February 8, 2006 by zeph Quote Share this post Link to post Share on other sites