Add the missing ‘case 2: …’.
If you are less patient, you can also try something like this (without long switch):
do
{
std::cin >> x;
std::cout << "enter any other number than " << ++j << std::endl;
} while( x != 5 && j < 10 );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hope this is right forum to post. Microsoft forums are so chaotic...
I Am trying to execute simple C++ program in VS community 19 on Windows 10.
#include <iostream>
int main()
{
int j{ 0 };
int x{ 0 };
std::cout << "enter any number other than 5\n";
do {
std::cin >> x;
switch (j){
case 0:
std::cout << "enter any other number than 1\n";
break;
case 1:
std::cout << "enter any other number than 2\n";
break;
case 3:
std::cout << "enter any other number than 3\n";
break;
case 4:
std::cout << "enter any other number than 4\n";
break;
case 5:
std::cout << "enter any other number than 5\n";
break;
case 6:
std::cout << "enter any other number than 6\n";
break;
case 7:
std::cout << "enter any other number than 7\n";
break;
case 8:
std::cout << "enter any other number than 8\n";
break;
case 9:
std::cout << "enter any other number than 9\n";
break;
case 10:
std::cout << "enter any other number than 10\n";
break;
}
j++;
} while (x != 5 && j < 10);
if (x == 5) {
std::cout << "you entered 5 you scoundrel";
}
else
std::cout << "you are more patient than I Am!";
return 0;
}
Problem happens on runtime, when I enter number for a third time (case 3:), console hangs and nothing happens. I pressed ctrl+c and it threw some weird error and showed window, that sources are not available for module kernelbase.dll, or something. I tried to load sources, but it didn't help. Now same window isn't showing, but this shows after program execution.
PS: tell me how to rename post title, I don't know how would I even call this error!
Thanks for help.
Add the missing ‘case 2: …’.
If you are less patient, you can also try something like this (without long switch):
do
{
std::cin >> x;
std::cout << "enter any other number than " << ++j << std::endl;
} while( x != 5 && j < 10 );
Your code has some bugs :
why switch (j) instead of switch (x) ?
there is no "case 2", so, as you test j, it does not display a message the 3rd time...
LOL I Am blind xDD
I supposed something was wrong with Windows/VS. As it complained about some sources for module kernelbase.dll and opened some weird window about some symbols missing, or something. This is not a standard behavior, after debugging.
I repaired cases and now it works fine.
Thanks for help!