I am asking this question again because the first expert answered my question by saying, " Step 1 I have executed the given code in online compiler as it is. Step 2 The code is executed successfully without any warnings and error. Sent a screenshot of the OUTPUT: ".
I am asking this question again because the first expert answered my question by saying, "
I have executed the given code in online compiler as it is.
The code is executed successfully without any warnings and error.
Sent a screenshot of the OUTPUT: ".
Unfortunately, for me that response did not help me at all. I am aware that the online compiler the expert use gives no error or warning ,but I am using Visual Studio, C++ compiler for Windows 10 and I did get one warning. I am hoping an expert will see my problem and the screenshot attached and will be able to help me by fixing this code. The question I asked and screenshot is below. I want to Thank you very much for your expert service.
Question and problem asked eariler
I have a problem with the
This is the instruction for the code below:
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
This is the code I am having a problem with.
#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]; // this is where the problem is. There's a warning of 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;
}
Expert Answer
I have executed the given code in online compiler as it is.
The code is executed successfully without any warnings and error
Here is the OUTPUT:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps