I wrote this program to input roll no, class, section and marks in five subjects with total marks in the end with percentage, but it auto exits at the cout << "Marks -\n"; line, here's the full program :
I don't know if this is what you want or not since I have no idea what this program is supposed to do. If you're using Visual then you need something like the line system("pause"); or else the program will just exit as soon as it's finished executing all the lines, which sometimes may seem like the program just spontaneously stops working. I think line 26 isn't what you want either. I think you may want the variable "perc" to be a type double and on line 26 I think you may want to use 500.0 instead of 500 but again I have no idea what this program is supposed to do.
I've already given the program word to word what I wrote, no I didn't know sec was for just numbers, so I tried changing the variable name to sect but that didn't work either, also I tried bool your program letter to letter but it's the same problem again, the program loads gets to the section line I enter a single alphabet 'A', 'B' without the quotes but then the program skips all the marks inputs for some reason, it just shows the output lines like "Hindi -" and thats it, then press any key to continue and the program fails, to be more precise without the system pause, debugging showed whenever I enter the section alphabet, there were couple of missing PDB file errors with kernel.dll and many others, some reason??
Your program is asking for an integer (number) and you are giving it a character (letter). This causes the input stream to error and it will not work anymore, which is why it skips all the inputs.
Console input is always tricky. Best approach I can think of is always assume the input is string. Then once your program read in the input, go and figure out if it is a "number string".
Alright guys after some thinking I finally found the solution! As you guys told me with int function you can't write a character, so I thought would it be possible to include 2 functions in one driver function? turns it out it did, so I used float for all the other variables and char for just section and magic! It worked! Now I am having a minor problem though, when total marks and percentage are displayed, they're displayed like this :
Total marks-
450Percentage -
90Press any key to continue...
Any way to separate the components out? I tried \n