How to compile with Eclipse

I have 2 c++ source files to put into my eclipse project and also a header file. How do I compile all of it to make an .exe file?
Last edited on
For one, don't use a character array to get direct input while also using cin. It tends to be... messy. In fact, that is exactly what is going on here. So, for the changes:

Make user[100] into string user. This isn't C, after all.

Replace cin >> user; with getline(cin, user);

From there, it should run fine.
Doesn't work. It still stop at after getting input of counter .
Odd. Worked fine on my end.
Last edited on
Hmm when I do that , it says that getline is not a recognized function.
Hence my retroactive redaction of my really stupid suggestion.
What compiler and IDE are you using??
closed account (48T7M4Gy)
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
#include <iostream>
#include <string>

using namespace std;

int main() {

	char user[100];
	int counter = 0;

	cout << "Enter Word : \n";
	cin >> user;

	cout << "Enter move count: \n";
	cin >> counter;

	for (int i = 0; user[i] != '\0'; i++)
	{
		user[i] = user[i] + counter;
		// still need to modify to ensure character is still alpha
	}
	
	cout << user;
	return 0;
}
What's all the '(i%91)+counter' business for in your indexing?

The wording of your question and your description of the problem seem a bit ambiguous. MOVING a character implies changing it's position within the array, but the description you gave suggests that you don't want to move it, just change it's value.

in either case the above indexing seems completely bizarre. I think what you were going for is just a straightforward
user[i]+=counter;
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
for (int i = 0; user[i] != '\0'; i++)
	{
		ch = user[i];

		if ( ch >= 97)
			user[i] = (user[i] + counter - 97) % 26 + 97;
		else
			user[i] = (user[i] + counter - 65) % 26 + 65;
	}
Hi
I think you should first change that input "cin >> user; to "cin >> user[0]; if u just want to use one element of the array. By the way, how can you say enter a word when you declared it as a character? I think you should prompt the user to enter a letter and not a word.
Last edited on
This is an encrypter... are you making a Caesar Cipher?

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

using namespace std;

int main() {

char user[100],ch;
int counter=0;
int i = 0;


cout<<"Enter Word : \n";
cin >> user;

cout<<"Enter move count: \n";
cin >>counter;

while ( user[i] != '\0'){
ch = user[i];
if ( ch >= 97)
user[i] = (user[i] + counter - 97) % 26 + 97;
else user[i] = (user[i] + counter - 65) % 26 + 65;
i++;}
cout<<endl<<user<<" <Here is the output";}
Last edited on
closed account (48T7M4Gy)
That's the way I interpreted the OP but it might be Caesar salad?
My question would be: What makes you think the for loop isn't running?
I have no idea that's why I'm asking... I'm not doing a cipher but yes you could see it that way but numbers and special characters must stay the same so @jasonwynn117 , it's not fully correct.

@cire : I think it has to do with string to char conversion or vice-versa.
Ok first of all I'm dumb because the loop was running but I didn't use cout to print the array =='
Last edited on
@cire : I think it has to do with string to char conversion or vice-versa.


If we take a short visit to: http://ideone.com/1z2vvK and add some output we can see that the string after the for loop runs is different than the string before the for loop ran... so what makes you think the for loop isn't running?
Thanks cire, I've fixed the problem already. Now another problem arises is that I want to compile 2 c++ source files and a header in Eclipse... How do I do that?
If you are changing the topic change the name of the forum post.
It would be better to start a new thread for a new topic.
Topic archived. No new replies allowed.