Guys I'm facing Compilation error mostly in string lines. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Guys I'm facing Compilation error mostly in string lines.

My integer codes work well. I have made 2codes. In strings I get stuck up. Please check these 2codes that I have made. Thanks. https://code.sololearn.com/cYc1A9t77Rnd/?ref=app https://code.sololearn.com/cEAicJ2I5J5r/?ref=app

1st Oct 2017, 9:56 PM
Miss Rashmi Lulla
15 Answers
+ 3
switch(com) { case 1: //code here break; case 2: //code here break; case 5: //code here break; default: //code here } You don't use a comparison operator at all. If the argument is equal to the value of the case, that case will be ran.
1st Oct 2017, 10:13 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Thanks a lot Chaotic. It's working. Thank you
1st Oct 2017, 10:25 PM
Miss Rashmi Lulla
+ 2
Thx forrest. I made that change. However, I am still facing Compilation error.
1st Oct 2017, 10:02 PM
Miss Rashmi Lulla
+ 2
I changed < to =. Is the switch case syntax proper now?
1st Oct 2017, 10:08 PM
Miss Rashmi Lulla
+ 2
In addition to incorrectly using tge switch/case statements as forest has stated: cin >> advisorname[i] >> endl; You can't input a value into endl as it is not a variable. Use something more like the code below instead. cin >> advisorname[i]; cout << endl;
1st Oct 2017, 10:10 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thx Chaotic. I will make these changes now.
1st Oct 2017, 10:12 PM
Miss Rashmi Lulla
+ 2
In case it helps, here's a modified version of the first one that uses correct syntax https://code.sololearn.com/cO7Kchou632R/#cpp
1st Oct 2017, 10:15 PM
forrest
+ 2
Thx so much Forrest for giving me detailed explanations of my errors. I am actually realising how to code after reading your explanation. I downloaded Code::Blocks. However, it just gives line nos where the error is. I will try to make the advisor login program again. In my sales commission program also, I made those changes that you suggested. It's working now. I am feeling happy. Thank you Forrest.
2nd Oct 2017, 4:40 AM
Miss Rashmi Lulla
+ 2
Forrest I have improvised my code. Now it is working partially. The glitch was that evenif you put a wrong userid it got accepted. Hence, I added a if statement at the end of the code. There is still some logical issue at the end of the code. I am feeling happy atleast something is working. Thank you Forrest.
3rd Oct 2017, 9:22 PM
Miss Rashmi Lulla
+ 1
hmm I suspect it's that newline you're trying to print
1st Oct 2017, 9:58 PM
forrest
+ 1
either make it a string or use endl
1st Oct 2017, 9:59 PM
forrest
+ 1
on further inspection, you should be using an if-else construct instead of a switch. the syntax here doesn't work because switch statements are meant to match specific values, not comparison operators
1st Oct 2017, 10:03 PM
forrest
+ 1
I fixed some errors in the second one as well, though it doesn't seem quite finished yet. Everything that changed has a commented line with "NOTE" that explains what changed and reasons for the change. I recommend trying out an IDE, especially for c++, because it will help catch the smaller syntax errors. https://code.sololearn.com/cBi2nReT3PwV/#cpp
1st Oct 2017, 11:30 PM
forrest
+ 1
Now my errors are in line 16 & 70 and both are related with curly brackets, in Advisors Logging in program. Line 16: A function definition is not allowed before { . Line 70 : expected } at the end of input.
2nd Oct 2017, 8:47 PM
Miss Rashmi Lulla
+ 1
You had an extra cout in newAdvisors, on line 21. Another thing to remember is that you can't define functions, instead declare them all sequentially. Your return value and closing brace to main shouldn't be at the end of the file, it should be right before newAdvisors starts. The last error was simply the do-while loops at the end. Make sure you close the brace before writing the while part on lines 65 and 66. One last tip is that you use indentation to mark sections of code in braces. Instead of needing to comment which braces close what, you can look for the matching indentation level. See the vertical bars in the code below for an example of what I mean: int main() { | do { | | if (...) { | | | ... | | } | } while(...); }
3rd Oct 2017, 12:04 AM
forrest