I have a problem with the program below. Line 31 give a warning of 3 dots (…) under the suf word suffix. I have attached a screenshot showing where the problem is and a message box stating what the problem is. If possible, can you fix this program problem please. Thank you Write a program in C++ that reads a sentence as input and converts each word to "Pig Latin." In one version, to convert a word to Pig Latin, your remove the first letter and place the letter at the end of the word. Then you append the string "ay" to the word. Here is an example: English: I SLEPT MOST OF THE NIGHT Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY Criteria program compiles 2) program solves problem according to specification 3) program declares, creates, or initializes static or dynamic array correctly 4) if required program defines function or functions with array parameters or array returns 5) program uses arrays to solve problem 6) program destroys any dynamic arrays #include #include #include using namespace std; string piglatin(string); string substr(string, int&); int main() { string input; cout << "Enter a sentence: "; getline(cin, input); cout << "Piglatin: " << piglatin(input) << endl << endl; return 0; } string piglatin(string input) { int len = 0, counter = 0, start = 0, stop = 0; string word = "", newstring = ""; do { word = substr(input, start); //translate the next word start++; newstring = newstring + word + " "; //add the word and a blank to the new sentence } while (start < input.length()); return newstring; } string substr(string s, int& n) { char word[50] = "", suffix[2]; // has warning, three ... under the suf of the word suffix[2]; int i = 0; suffix[0] = s[n]; //get the first letter suffix[1] = '\0'; n++; while (s[n] != ' ' && s[n] != '\0') //copy letters from the input to the new word until end of the word { word[i] = s[n]; n++; i++; } strcat(word, suffix); //add the suffix created to the new word strcat(word, "ay"); //add "ay" to it return word; }
I have a problem with the program below. Line 31 give a warning of 3 dots (…) under the suf word suffix. I have attached a screenshot showing where the problem is and a message box stating what the problem is. If possible, can you fix this program problem please. Thank you
Write a program in C++ that reads a sentence as input and converts each word to "Pig Latin." In one version, to convert a word to Pig Latin, your remove the first letter and place the letter at the end of the word. Then you append the string "ay" to the word. Here is an example:
English: I SLEPT MOST OF THE NIGHT
Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
Criteria
- program compiles
2) program solves problem according to specification
3) program declares, creates, or initializes static or dynamic array correctly
4) if required program defines function or functions with array parameters or array returns
5) program uses arrays to solve problem
6) program destroys any dynamic arrays
#include<iostream>
#include <cstring>
#include <string>
using namespace std;
string piglatin(string);
string substr(string, int&);
int main()
{
string input;
cout << "Enter a sentence: ";
getline(cin, input);
cout << "Piglatin: " << piglatin(input) << endl << endl;
return 0;
}
string piglatin(string input)
{
int len = 0, counter = 0, start = 0, stop = 0;
string word = "", newstring = "";
do
{
word = substr(input, start); //translate the next word
start++;
newstring = newstring + word + " "; //add the word and a blank to the new sentence
} while (start < input.length());
return newstring;
}
string substr(string s, int& n)
{
char word[50] = "", suffix[2]; // has warning, three ... under the suf of the word suffix[2];
int i = 0;
suffix[0] = s[n]; //get the first letter
suffix[1] = '\0';
n++;
while (s[n] != ' ' && s[n] != '\0') //copy letters from the input to the new word until end of the word
{
word[i] = s[n];
n++;
i++;
}
strcat(word, suffix); //add the suffix created to the new word
strcat(word, "ay"); //add "ay" to it
return word;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 4 images