encoder not encoding a sentence


my encoder will not encode anything after it sees a space I used the getline function but that doesnot help if my phrase is welcome here the only thing encoded is welcome I have put all of them to cin but that doesnot change anything and when I change to getline I get an error stating that:no matching function for call to 'getline(std::istream&, char&)'and no matching function for call to 'getline(std::istream&, int&)'


# include <iostream>
# include <string>
using namespace std;


int main()// declaration of main
{
char first,last, b;//declaration of char variables
bool pass=false, found = false;//declaration of bolean values
int a,length,count; //declaration of int varibles
string code;// declaration of string

while (pass==false)//declaration of while loop

{
cout << "\nThis program will encrypt the entered text using Caesar Cipher." << endl;
cout<< "Please input the fisrt letter of the alapabet to begin encoding from(a-z)then press enter\n"; //output statememt
cin>> first;//input statement
cout<<"Please enter the last letter of the alaphabet that you wish encoding to stop then press enter(a-z)\n";// output statement
cin>> last;//input statement

if ( isalpha(first)&& isalpha (last))//decalaration of if statement
{

pass=true;// declaration of test statement
}
else
{
cout<<"Invalid statement please enter a alaphabet between (a-z)\n";//declaration of output statement

}
}
label:// declaration of a label
cout<<"Please enter the amount you want the code to shift by(number 1-24)\n";//declaration of output statement
cin>> a; // input statement




cout<<"Please enter text that you wish to be encoded\n";//declaration of output statement
cin>>code;//declaration of input statement
getline(cin,code);


length = (int)code.length();// set the length to however long the input is calling its member function


for ( count = 0; count < length; count++)// declation of for loop
{
if ( isalpha(code[count]))//declaration of character if statement
{
for ( int i=0; i < a; i++) //declaration of for loop
{


if( code[count]=='z' && last != 'z')
{
code[count]='a';
code[count]++; // else continue to alphabet
}
else
{


if( code[count]=='z' && last == 'z')
{
code[count]=first;
code[count]++; // else continue to alphabet

}
else
{

if(code[count]==last)// when the character reaches Z the next character would be a
{
code[count]=first;
}
else
{
code[count]++;
}



}
}
}
}
}


cout << "\nYour ciphered code is: " << code << endl;

cin.get();
}






use the code tags and proper indentation please
As requested by Need4Sleep i spent little time to edit code for "proper" grammar

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# include <iostream>
# include <string>
using namespace std;

int main()// declaration of main
{
	char first,last, b;//declaration of char variables
	bool pass=false, found = false;//declaration of bolean values
	int a,length,count; //declaration of int varibles
	string code;// declaration of string

	while (pass==false)//declaration of while loop
	{
		cout << "\nThis program will encrypt the entered text using Caesar Cipher." << endl;
		cout<< "Please input the fisrt letter of the alapabet to begin encoding from(a-z)then press enter\n"; //output statememt
		cin>> first;//input statement
		cout<<"Please enter the last letter of the alaphabet that you wish encoding to stop then press enter(a-z)\n";// output statement
		cin>> last;//input statement

		if ( isalpha(first)&& isalpha (last))//decalaration of if statement
		{
			pass=true;// declaration of test statement
		}
		else
		{
			cout<<"Invalid statement please enter a alaphabet between (a-z)\n";//declaration of output statement

		}
	}

	label:// declaration of a label
	cout<<"Please enter the amount you want the code to shift by(number 1-24)\n";//declaration of output statement
	cin>> a; // input statement

	cout<<"Please enter text that you wish to be encoded\n";//declaration of output statement
	cin>>code;//declaration of input statement
	getline(cin,code);

	length = (int)code.length();// set the length to however long the input is calling its member function

	for ( count = 0; count < length; count++)// declation of for loop
	{
		if ( isalpha(code[count]))//declaration of character if statement
		{
			for ( int i=0; i < a; i++) //declaration of for loop
			{
				if( code[count]=='z' && last != 'z')
				{
					code[count]='a';
					code[count]++; // else continue to alphabet
				}
				else
				{
					if( code[count]=='z' && last == 'z')
					{
						code[count]=first;
						code[count]++; // else continue to alphabet
					}
					else
					{
						if(code[count]==last)// when the character reaches Z the next character would be a
						{
							code[count]=first;
						}
						else
						{
							code[count]++;
						}
					}
				}
			}
		}
	}

	cout << "\nYour ciphered code is: " << code << endl;

	cin.get();
}


See errors now? =)
Last edited on
That code doesn't match up with the errors you posted. I don't see anywhere where you are trying to getline into an int or a char.
Topic archived. No new replies allowed.