Asterisk as Character

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;
}
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 :)
Character literals are placed in single quotes: std::cout << '*';
I have a slightly different question now: how do I change the following code to output an array of prime numbers along with numbers that are not prime represented by the asterisk?

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
#include <iostream>

using namespace std;

int main()
{
    int A, B, i;
    std::cout << '*';
    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;
}
http://people.stfx.ca/mlin/cs161/index.html

If it clears anything up about my question, the link above leads to the actual assignment question (the first one)
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
||=== Build: Debug in Assignment 3 Q1 (compiler: GNU GCC Compiler) ===|
ld.exe||cannot open output file bin\Debug\Assignment 3 Q1.exe Permission denied|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


I got this as an error when I tried to build and run the program
looks like your IDE cant run the executable
this is usually happens when the process is still running in another window :)
Last edited on
What do I do about this?
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?
I only have it up in one window. And it ran fine before.
I just reverted it back to what it was before and I received the same error
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
Would typing it in fix it as well? (Because I just copied it over)
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
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.
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
Registered users can post here. Sign in or register to post.