Asterisk as Character

Nov 3, 2017 at 9:15pm
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
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
Character literals are placed in single quotes: std::cout << '*';
Nov 3, 2017 at 11:08pm
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;
}
Nov 3, 2017 at 11:21pm
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)
Nov 3, 2017 at 11:27pm
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
Nov 3, 2017 at 11:31pm
||=== 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
Nov 3, 2017 at 11:36pm
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
Nov 3, 2017 at 11:37pm
What do I do about this?
Nov 3, 2017 at 11:43pm
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
I only have it up in one window. And it ran fine before.
Nov 3, 2017 at 11:56pm
I just reverted it back to what it was before and I received the same error
Nov 4, 2017 at 12:00am
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
Would typing it in fix it as well? (Because I just copied it over)
Nov 4, 2017 at 12:05am
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
Nov 4, 2017 at 1:03am
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
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
Topic archived. No new replies allowed.