![]() |
| ||
| While Loops Help Please Hi all I am learning C++ , but am still pretty new to it I have one problem I am writing a program to simply input a mark and then it gives the corresponding symbol and according to the symbol if its anything above an E it displays you pass and if not it displays you dont , I have had no problem writing this : [ // Symbol issuing program as per mark out of 100. #include <iostream> using namespace std; int symbol(int mark) { if (mark >= 0 && mark <= 39) return 70; if (mark >= 40 && mark <= 49) return 69; if (mark >= 50 && mark <= 59) return 68; if (mark >= 60 && mark <= 69) return 67; if (mark >= 70 && mark <= 79) return 66; if (mark >= 80 && mark <= 100) return 65; } bool passOrNot (char symb) { char A, B, C, D, E , F; if (symb <= 68 ) return 1; } int main() { int mark; char symb; cout << "Enter marks out of 100 followed by -10 to end inputs and display the results: "; cin >> mark; symb = symbol(mark); cout << "Symbol corresponding to " << mark << " is " << symb; if (passOrNot (symb)) cout << " You Pass Congratulations!"<< endl; else cout << " Unfortunately you fail" << endl; return 0; } ] Except now I want to impliment a While loop into it so that I can enter a number of marks followed by -10 (or any defined number below 0) to end my inputs and display the results of each mark , yet everything I try doesnt work , it either gets stuck in a loop or simply stops on my 1st number entered , Please could somebody help me out here. |
| ||
| Re: While Loops Help Please Basically I have this but entering -10 doesnt end it??? [// Symbol issuing program as per mark out of 100. #include <iostream> using namespace std; int symbol(int mark) { if (mark >= 0 && mark <= 39) return 70; if (mark >= 40 && mark <= 49) return 69; if (mark >= 50 && mark <= 59) return 68; if (mark >= 60 && mark <= 69) return 67; if (mark >= 70 && mark <= 79) return 66; if (mark >= 80 && mark <= 100) return 65; } bool passOrNot (char symb) { char A, B, C, D, E , F; if (symb <= 68 ) return 1; } int main() { int mark; char symb; mark = 1; while (mark != -10, mark++){ cout << "Enter mark out of 100 , enter -10 to end: "; cin >> mark; symb = symbol(mark); cout << "Symbol corresponding to " << mark << " is " << symb; if (passOrNot (symb)) cout << " You Pass Congratulations!"<< endl; else cout << " Unfortunately you fail" << endl; } return 0; } ] |
| ||
| Re: While Loops Help Please You have an error here: while (mark != -10, mark++) Change it to: while (mark != -10) And the program will end when -10 is entered The next time you post code, please use code tags |
| ||
| Re: While Loops Help Please Thanks very much I cant believe i didnt realise that , works perfectly now . I just joined today though and am wandering what you meant by PM's asking for help will be ignored? Thanks |
| ||
| Re: While Loops Help Please You can send Private Messages (PM) to people by clicking on their name and select 'send Private Message' But I got a lot of PM's of people begging me for source-code and it irritated the hell out of me. So I added a signature PM's asking for help will be ignored.. so everyone can see that PMing me won't help them. The signature will display in every message I post. To add a signature of your own, goto 'control panel' (top of the screen) and click 'edit signature' |
| All times are GMT -4. The time now is 11:29 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC