Nov 3, 2017 at 9:15pm UTC
Can I define the asterisk as a character/variable?
#include <iostream>
using namespace std;
int main()
{
int A, B, i;
char *;
cout << "Enter a starting number: " << endl;
cin >> A;
cout << "Enter an ending number: " << endl;
cin >> B;
while (i < A)
{
if (A % i == 0)
{
cout << A;
}
else (A % i != 0);
{
cout << *;
}
A++;
}
return A;
}
Nov 3, 2017 at 10:31pm UTC
Again, im no expert but
id assume: No, since its used for specifying pointer types
you'll just have to name it something else.
dont see why you would name a variable * anyway :)
Nov 3, 2017 at 10:47pm UTC
Character literals are placed in single quotes: std::cout << '*' ;
Nov 3, 2017 at 11:27pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include <iostream>
using namespace std;
int main ()
{
int A, B;
cout << '*' ;
cout << "Enter a starting number: " << endl;
cin >> A;
cout << "Enter an ending number: " << endl;
cin >> B;
cout << endl;
for (int i = A; i < B; i++)
{
bool prime = true ;
for (int j=2; j*j <= i;j++)
{
if (i % j == 0)
{
prime = false ;
break ;
}
}
if (prime)
cout << i << endl;
else
cout << "*" << endl;
}
return 0;
}
i took the liberty to change your while loop to a for loop :)
Last edited on Nov 3, 2017 at 11:27pm UTC
Nov 3, 2017 at 11:36pm UTC
looks like your IDE cant run the executable
this is usually happens when the process is still running in another window :)
Last edited on Nov 4, 2017 at 12:08am UTC
Nov 3, 2017 at 11:43pm UTC
have you made sure the program isn't already running in another window?
if so, and it still doesn't work you might have to restart your computer
if you revert back to your previous code, does it run? or do you get the same error?
Nov 3, 2017 at 11:44pm UTC
I only have it up in one window. And it ran fine before.
Nov 3, 2017 at 11:56pm UTC
I just reverted it back to what it was before and I received the same error
Nov 4, 2017 at 12:00am UTC
most likely one of your previous programs crashed and didn't get shut down correctly and is still running in the background.
Restarting your computer should fix this
Nov 4, 2017 at 12:02am UTC
Would typing it in fix it as well? (Because I just copied it over)
Nov 4, 2017 at 12:05am UTC
no, its no the code thats the problem.
you see, your code editor cannot run the code because an error must have happened during the last time it ran.
the only way to fix this is to restart your computer im afraid
or manually go in to task manager and kill the process
Last edited on Nov 4, 2017 at 12:06am UTC
Nov 4, 2017 at 1:03am UTC
stav is correct. The compiler is telling you that it can't write to the executable file because it is locked by another process. There's nothing with the code that could generate that error.
Nov 4, 2017 at 1:56am UTC
windows task manager, kill q1.exe
happens from time to time when you crash, but restarting the computer is overkill most of the time.
Last edited on Nov 4, 2017 at 1:57am UTC