hello -
I'm lost and trying to write a program that takes in a sentence from the User and converts it to pig latin. That is, remove each first letter of a work and place it at the end of the word. I'm stumped. I can't even get my mind around this and I've been on it for 4 hours. If someone could provide me with some helpful hints, I would great appreciate it.
#include <iostream>
#include <cctype>
#include <string>
#include <cstring>
#include <stdio.h>
usingnamespace std;
//Function Prototype
void translateUser(int); //Function prototype
int main()
int SIZE = 256; //Max size of string
int userInput[256]; //String Input
int count = 0; //Counter
int num = 0; //counter for pointer conversion
//Get the User's input.
cout << "Please enter a sentence and hit the Return key when complete. \n";
cin.getline(userInput);
//Search the array for "0" or \0 values
StrPtr=&string[0];
while (*StrPtr!='\0')
{
for (count = 0; count < SIZE; count++)
{
if (isspace(string))
//If it's a space, must do something
cout << "space encountered n\";
if ((isalpha(string) || isdigit(string))
//If a letter occurs, move on
cout << count[] << endl;
}
return 0;
}
}
Looks like you're missing an opening brace of your main() function.
Now, you would probably be best of using std::string over c-strings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <sstream>
std::string input, tmp;
//Get the User's input.
cout << "Please enter a sentence and hit the Return key when complete. \n";
cin.getline(input);
std::istringstream iss(input); //temporary stringstream
while (iss >> tmp) //while there are words in the sentence
{
char first = tmp[0]; //get first character
tmp.erase(0,1); //erase first character
tmp.append(first); //put first character at the back
std::cout << tmp;
}
That should get you on your way, please do let us know if you require any further help.
I obviously don't know what I am doing. I was told I need to use the C++ string class. Even a more difficult understanding now for me....
Thank you for your suggestions and time
#include <string>
#include <iostream>
usingnamespace std;
int main(){
string tmp = "cat";
string end = "t";
char first = tmp.at(0); //get first character
tmp.erase(0, 1); //erase first character
tmp += first; //append char first to string tmp
tmp.append(end); //append additional content to string
cout << tmp; //cat is now atct
return 0;
}