Desperate for help!

I'm in need of assistance for this homework assignment I'm on. Unfortunately my teacher has ignored my message requesting assistance so I'm on my own. The lab is to translate English to Pig Latin in a string of text, or in more than one word of text. EX: Welcome to Coding.

I don't care about the rules given to me so long as I have a working code, and unfortunately, I can't get my code to work with me. I'm very lost and confused on how to finish this.

I would appreciate any assistance at all to figure this out.

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
  #include <iostream>
#include <string>
#include <fstream>

using namespace std;


int pLatin(string &s1, int &rtrnNum, int &end);
void find(string &s1, int &end);


int main()
{
	//Declarations
	int rtrnNum = 0; //temporary number for return value of main
	string entry; //original text entered
	string temp;
	int tempN = 0; //save the vowel's position in the word
	int i = 0;
	//Prompt
	cout << "This program takes a string of words and coverts it to pig latin." << endl;
	while (i == 0)
	{
		//Input
		cout << "Enter a string of words, or press Enter to quit." << endl; 
		getline(cin, entry); //input line of text
		cout << entry << endl;//displays original text
		string s1(entry);
		cout << "The string you entered was, "<< s1.length() << " characters long." << endl;
		int end = s1.length();
		pLatin(s1, rtrnNum, end); //calls function
		if (rtrnNum > 0) //Return Value
		{
			return 1;
		}
		else
		{
			return i;
		}
	}
}

int pLatin(string &s1, int &rtrnNum, int &end)
{
	//declarations
	int i = 0; //condition for While
	if (s1 == "")
	{
		return 1;
	}
	while (i == 0)
	{
		find(s1, end);
	}
}
void find(string &s1, int &end)
{
	//See if fist letter of entry starts with vowel
	if (s1.at(0) == 'a' || s1.at(0) == 'e' || s1.at(0) == 'i' || s1.at(0) == 'o' || s1.at(0) =='u')
	{
		s1 = s1 + "hay";
	}
	else
	{
		s1.find('a');
		if (s1.at(2) = 'a')
		{
			s1.insert(end, s1.at(0,1));
			s1.erase(end, s1.at(0));
			s1.insert(end, "hay");
		}
		}
	
}
Last edited on
foo.cpp: In function ‘int main()’:
foo.cpp: In function ‘void find(std::string&, int&)’:
foo.cpp:66:21: warning: suggest parentheses around assignment used as truth value
foo.cpp:68:28: error: no matching function for call to ‘std::basic_string<char>::at(int, int)’
/usr/include/c++/4.8.2/bits/basic_string.h:883:7: note:   candidate expects 1 argument, 2 provided
foo.cpp: In function ‘int pLatin(std::string&, int&, int&)’:
foo.cpp:55:1: warning: control reaches end of non-void function


> I can't get my code to work with me
you need to be more descriptive
Per the compiler diagnostics ne555 supplied:

Line 66: You're using the assignment operator, not the comparison operator. The comparison operator is ==.

Line 55: You have no return statement at the bottom of the function.

Lines 34,38: Why are you returning 1? Returning non-zero from main usually tells the operating system that the program failed, although this is OS dependent. Also, you will never make more than one pass through the while loop, since you will always execute a return out of main on the first pass.
Line 68: there is no std::string::at() that takes 2 arguments
¿what was your intention there?
That's the thing, I'm not all entirely sure of what I was doing. The explanations in my homework assignment don't make sense to me at all, so I was trying to write the code without fully understanding what was needed. I'm still not entirely sure what is needed.

My code is crap because I can't understand what I'm doing, which is why I've consulted these forums. I asked about the assignment earlier this week, but received no answer so I just read my book and hoped for the best.

My intention with line 68 was to enter the two characters from string to the end of the string and then add hay, but even then it probably wouldn't have worked as I'd have liked because it should have the opportunity to be a multiple string word.

I had no idea returning one was telling the program it failed, so thanks for that.

Assignment below.

Would anyone be totally averse to writing a pseudo code with more detail on what some of these things mean? Once I got to the part I mention in this forum I got really confused and started to stray from the lab instructions.
http://www.cplusplus.com/forum/beginner/128227/
Topic archived. No new replies allowed.