Hi
I have the following code which is my project
I completed section 1 and 2 but it doesn't work
could you help figuring why?
#include<iostream>
#include<string>
using namespace std;
void count();
void reverse();
void encode();
void decode();
int selection;
int main()
{
cout<<"******************"<<endl;
cout<<"Welcome To Project"<<endl;
cout<<"******************"<<endl;
cout<<endl;
cout<<"Please choose from the following menu or 0 to exit"<<endl;
cout<<"1 - Count Characters of a string."<<endl;
cout<<"2 - Reverse a string."<<endl;
cout<<"3 - Encode a string."<<endl;
cout<<"4 - Decode a string."<<endl;
cin>>selection;
while(selection != 0)
{
switch(selection)
{
case 1:
count();
break;
case 2:
reverse();
break;
case 3:
encode();
break;
case 4:
decode();
break;
default:
cout<<"You did not choose from the list";
break;
}
}
return 0;
}
void count()
{
string str;
int spaces=0;
int words=0;
cout<<endl;
cout<<"Enter a string: "<<endl;
getline(cin,str);
for(int i=0;i<=str.length()-1;i++)
{
if(str[i]==' ')
spaces++;
}
words = spaces + 1;
cout<<endl;
cout<<"Number of characters is: "<<str.length()<<endl;
cout<<"Number of spaces is: "<<spaces<<endl;
cout<<"Number of words is: "<<words<<endl;
selection=0;
}
void reverse()
{
string str;
string rstr;
cout<<endl;
cout<<"Enter a string: ";
getline(cin,str);
for(int i=str.length()-1;i>=0;i--)
{
rstr += str[i];
}
cout<<endl<<rstr;
selection=0;
}
void encode()
{
}
void decode()
{
}