Sidewalk Surfboard Posted September 28, 2015 Share Posted September 28, 2015 I did something wrong Quote Link to comment Share on other sites More sharing options...
Kalmor Posted September 28, 2015 Share Posted September 28, 2015 It'd be more helpful if you posted the code. Quote Link to comment Share on other sites More sharing options...
Sidewalk Surfboard Posted September 28, 2015 Author Share Posted September 28, 2015 I fixed it, thank god, but that spooked me Quote Link to comment Share on other sites More sharing options...
Irreverent Posted September 28, 2015 Share Posted September 28, 2015 Clearly you neglected to insert a valid month..... 1 Quote Link to comment Share on other sites More sharing options...
Kaedal Posted September 28, 2015 Share Posted September 28, 2015 There's something almost artistic about that. Quote Link to comment Share on other sites More sharing options...
ArielMT Posted September 28, 2015 Share Posted September 28, 2015 OP, I'm going to have to ask you to post code or something else that helps next time.There's something almost artistic about that.It's almost an ASCII snowcrash. 1 Quote Link to comment Share on other sites More sharing options...
Sar Posted September 28, 2015 Share Posted September 28, 2015 I'm going out on a limb and guess you messed up a loop related to how it handles invalid months. Quote Link to comment Share on other sites More sharing options...
Sidewalk Surfboard Posted September 29, 2015 Author Share Posted September 29, 2015 Ok, new error popped up. This time I have my code. The error is that every time I press a key to continue, it just looks "insert a valid month" and "press a key to continue" forever.#include <iostream>#include <string>using namespace std;int main(){Â Â Â int month;Â Â Â start:Â Â Â cout <<"Birth Gem Database";Â Â Â cout << endl;Â Â Â cout <<"Please enter your birth month (number): ";Â Â Â cin >> month;Â Â Â cout << endl;Â Â Â if(month==1){Â Â Â Â Â Â cout <<"Your birth gem is Garnet.";Â Â Â }Â Â Â if(month==2){Â Â Â Â Â Â cout <<"Your birth gem is Amethyst.";Â Â Â }Â Â Â if(month==3){Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cout <<"Your birth gem is Aquamarine.";Â Â Â }Â Â Â if(month==4){Â Â Â Â Â Â cout <<"Your birth gem is Diamond.";Â Â Â }Â Â Â if(month==5){Â Â Â Â Â Â cout <<"Your birth gem is Emerald.";Â Â Â }Â Â Â if(month==6){Â Â Â Â Â Â cout <<"Your birth gem is Alexandrite.";Â Â Â }Â Â Â if(month==7){Â Â Â Â Â Â cout <<"Your birth gem is Ruby.";Â Â Â }Â Â Â if(month==8){Â Â Â Â Â Â cout <<"Your birth gem is Peridot.";Â Â Â }Â Â Â if(month==9){Â Â Â Â Â Â cout <<"Your birth gem is Sapphire.";Â Â Â }Â Â Â if(month==10){Â Â Â Â Â Â cout <<"Your birth gem is Tourmaline.";Â Â Â }Â Â Â if(month==11){Â Â Â Â Â Â cout <<"Your birth gem is Citrine.";Â Â Â }Â Â Â if(month==12){Â Â Â Â Â Â cout <<"Your birth gem is Blue Zircon.";Â Â Â cout << endl;Â Â Â system ("pause");Â Â Â return 0;Â Â Â }Â Â Â else{Â Â Â Â Â Â cout << "Insert a valid month.";Â Â Â Â Â Â cout << endl;Â Â Â Â Â Â system ("pause");Â Â Â Â Â Â cout << endl;Â Â Â Â Â Â goto start;Â Â Â }Â Â Â return 0;}Â Â Â Quote Link to comment Share on other sites More sharing options...
ArielMT Posted September 29, 2015 Share Posted September 29, 2015 You need "else if" keywords to join the tests together, but honestly with that many choices to test a single variable for, you'd do a world better for readability to use a switch statement. Example:switch (x) { case 1: cout << "x is 1"; break; case 2: cout << "x is 2"; break; default: cout << "value of x unknown"; } Quote Link to comment Share on other sites More sharing options...
fennecbyte Posted September 29, 2015 Share Posted September 29, 2015 Here's some working code for you:#include <iostream> #include <string> using namespace std; int main() { int month; start: cout <<"Birth Gem Database"<<endl; cout <<"Please enter your birth month (number): "; cin >> month; cout << endl; if(month==1) cout <<"Your birth gem is Garnet."; else if(month==2) cout <<"Your birth gem is Amethyst."; else if(month==3) cout <<"Your birth gem is Aquamarine."; else if(month==4) cout <<"Your birth gem is Diamond."; else if(month==5) cout <<"Your birth gem is Emerald."; else if(month==6) cout <<"Your birth gem is Alexandrite."; else if(month==7) cout <<"Your birth gem is Ruby."; else if(month==8) cout <<"Your birth gem is Peridot."; else if(month==9) cout <<"Your birth gem is Sapphire."; else if(month==10) cout <<"Your birth gem is Tourmaline."; else if(month==11) cout <<"Your birth gem is Citrine."; else if(month==12) cout <<"Your birth gem is Blue Zircon."; else { cout << "Insert a valid month."; cout << endl; system ("pause"); cout << endl; goto start; } cout << endl; system ("pause"); return 0; } Your issue was how you did the if statements. For example, if you pick 8 for the month, it goes through and checks each value. Once it checks with the right one, it prints out the text, then continues checking with the others. It checks with 12, fails, then executes the code in the else statement, which restarts your program.Also, don't use goto with C++ code. Use a loop and then break out of it using break.Another thing, you don't need braces after if when you're only going to do a single command.Lastly, you could use switch for checking the months, like this:switch(month){ case 1: cout <<"Your birth gem is Garnet."; break; case 2: cout <<"Your birth gem is Amethyst."; break; case 3: cout <<"Your birth gem is Aquamarine."; break; case 4: cout <<"Your birth gem is Diamond."; break; case 5: cout <<"Your birth gem is Emerald."; break; case 6: cout <<"Your birth gem is Alexandrite."; break; case 7: cout <<"Your birth gem is Ruby."; break; case 8: cout <<"Your birth gem is Peridot."; break; case 9: cout <<"Your birth gem is Sapphire."; break; case 10: cout <<"Your birth gem is Tourmaline."; break; case 11: cout <<"Your birth gem is Citrine."; break; case 12: cout <<"Your birth gem is Blue Zircon."; break; default: cout << "Insert a valid month."; cout << endl; system ("pause"); cout << endl; goto start; }Â Quote Link to comment Share on other sites More sharing options...
ArielMT Posted September 29, 2015 Share Posted September 29, 2015 Also, you can remove the need for goto by putting the whole function, all but the return statement, inside a do-while loop. Quote Link to comment Share on other sites More sharing options...
Sidewalk Surfboard Posted September 30, 2015 Author Share Posted September 30, 2015 I was able to fix this but it still made me laugh Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.