473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error compilation because of "word"

i got the following error when compiling the codes..

the name 'word' does not exist in the class or namespace 'SimpleMath.Pig'

Can anyone troubleshoot on this . Thank you

//////////////////////
using System;

namespace SimpleMath

{

/// <summary>

/// Pig Latin interpreter

/// Demonstrate loops, string methods

/// Andy Harris, 11/16/01

/// </summary>

class Pig

{

static void Main(string[] args)

{

string pigWord = "";

string sentence = "";

string firstLetter;

string restOfWord;

string vowels = "AEIOUaeiou";

int letterPos;

while (sentence.ToLower() != "quit"){

Console.WriteLine("Please enter a sentence (or type "quit"to exit)");

sentence = Console.ReadLine();

foreach (string word in sentence.Split())

firstLetter = word.Substring(0,1);

restOfWord = word.Substring(1, word.Length -1);
letterPos = vowels.IndexOf(firstLetter);

if (letterPos == -1)

{

//it's a consonant

pigWord = restOfWord + firstLetter + "ay";

} else {

//it's a vowel

pigWord = word + "way";

} // end if

Console.Write("{0} ", pigWord);
//debugging code

//Console.Write("{0}", word);

//Console.Write("{0}", firstLetter);

//Console.Write("{0}", restOfWord);

//Console.Write("{0}", letterPos);

//Console.WriteLine("{0}", pigWord);
}

}

}

}


Nov 15 '05 #1
1 1376
missing "{", the scope of word is just the statement
following the foreach.

foreach (string word in sentence.Split())
{
-----Original Message-----
i got the following error when compiling the codes..

the name 'word' does not exist in the class or namespace 'SimpleMath.Pig'
Can anyone troubleshoot on this . Thank you

//////////////////////
using System;

namespace SimpleMath

{

/// <summary>

/// Pig Latin interpreter

/// Demonstrate loops, string methods

/// Andy Harris, 11/16/01

/// </summary>

class Pig

{

static void Main(string[] args)

{

string pigWord = "";

string sentence = "";

string firstLetter;

string restOfWord;

string vowels = "AEIOUaeiou";

int letterPos;

while (sentence.ToLower() != "quit"){

Console.WriteLine("Please enter a sentence (or type "quit"to exit)");
sentence = Console.ReadLine();

foreach (string word in sentence.Split())

firstLetter = word.Substring(0,1);

restOfWord = word.Substring(1, word.Length -1);
letterPos = vowels.IndexOf(firstLetter);

if (letterPos == -1)

{

//it's a consonant

pigWord = restOfWord + firstLetter + "ay";

} else {

//it's a vowel

pigWord = word + "way";

} // end if

Console.Write("{0} ", pigWord);
//debugging code

//Console.Write("{0}", word);

//Console.Write("{0}", firstLetter);

//Console.Write("{0}", restOfWord);

//Console.Write("{0}", letterPos);

//Console.WriteLine("{0}", pigWord);
}

}

}

}


.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Roys | last post by:
Hi Im doing something wrong in quitting the Word.Application in my VB program. I have General Declarations Dim AppWord As Word.Application Form_Load() Set AppWord =...
2
by: Jessard | last post by:
Hi All, I am writing a .NET app that accesses an access View. The view has a table column called 'Position'. When i try and right an UpdateCommand string for this using this column I am...
3
by: gdogg1587 | last post by:
Greetings. I'm working on a program that will "descramble" words. Think of a word scramble game where there is a list of characters, and several blank spaces to denote the word(s) that you are...
2
by: MaxiWheat | last post by:
Hi, I am using a software that uses MS Word to create PDF files. When I try to run the sample code (ASP 3.0), I get an error on this statement : Set oWord =...
2
by: Claus - Arcolutions | last post by:
I got a word document as a stream, and I want to get the text from the word document. But I cant seem to find anything to use for that purpose. The "Microsoft office ?.object" com reference, only...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
4
by: adam.timberlake | last post by:
Me again! I am trying to create a currency converter function for my eCommerce that still pet treats. I am a little short on money recently and so cannot afford a programmer. Can somebody tell me...
0
by: Vinodsrvk | last post by:
I tried to execute the bellow query for the word "about" in the NARRATIVE field. This narrative field is of CLOB type with NOTNULL SELECT SEARCHID, NARRATIVE FROM S.TBLSEARCH WHERE...
11
by: arnuld | last post by:
C takes input character by character. I did not find any Standard Library function that can take a word as input. So I want to write one of my own to be used with "Self Referential Structures" of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.