5ophie2012 17 Newbie Poster

I'm not sure what you mean by "results my formulas indicates". What exactly is your formula? I suggest doing all of the calculations with pen and paper, confirming what exactly you want to do, and then developing the algorithm. coding will come easier once you have that down.

5ophie2012 17 Newbie Poster

Try downloading this:
libusb-win32

it's a USB library that allows you to access installed USB devices

Ancient Dragon commented: nice :) +17
5ophie2012 17 Newbie Poster

you have to update the moneyowed within the loop:
and, you don't need the monthly variable.

#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;

int main()
{
	double interest, principle, moneyowed, payment;
	cout <<"I have been loaned $10,000.00 for my vehicle." << endl;
	moneyowed = 10000.00;
	payment = 300.00;	 //monthly payments of $300.00
	interest =(moneyowed * .0075); //annual interest rate of 9% but .75% per month
        principle=(payment-interest);
	
	cout <<"Month \t Money Owed" << endl;
	cout <<"-----------------------"<<endl;

	int num = 1; // 1 for the first month, 2 for the second, etc...
	while (num <= 10) // for 10 months, loop and decrement the money you owe
	{

		moneyowed=(moneyowed-principle); // update the moneyowed and display it
		cout<<num<<"\t\t"<<moneyowed<<endl;
		num++;
	
	}
	return 0;
}

hope this helps

5ophie2012 17 Newbie Poster

Looking at the book they seem to jump from topic to topic with no regards to grouping like items together. You'd be better off getting C# 4.0 in a Nutshell

I have LINQ Pad with 'C# in a NutShell 4.0 samples. I've been messing around with it, it seems to help a little bit.

5ophie2012 17 Newbie Poster

What book(s) does the class ask you to get?

Essential C# 4.0 and Primer C++

5ophie2012 17 Newbie Poster

thats pretty much what I had, except I didn't create a method for printing out all of the count information, I just did that in Main(). Also, I converted my char to a string so I could format it into hex characters...it seemed easiest for me. For example, my if statements would look like this in the CountIt() method:

if (letters == ' ' || letters == '\t' || letters == '\n')
        {
            status = false;
            wordcount++;

        }

And don't worry, your intellectual property is yours and yours only... I wouldn't recommend anyone copying someone else's code because you wouldn't learn anything anyways. It's interesting to see how other people approach the same problem.

5ophie2012 17 Newbie Poster

you are in my class. XD
I'm trying to figure the same shit out.

Wyatt doesn't really provide the kind of teaching that I expect from a university, the fact that I have to google every concept is piss poor.

Hope you are having an easier time than I am.

I'm doing as much as I can on my own, reading books and online material. but sometimes I have to ask questions on here...It usually helps. The only part I'm stuck on is counting words. I can count the words if there is only 1 whitespace in between, but what if there is multiple tabs/spaces? that's what I cant figure out. What are you having trouble with?

5ophie2012 17 Newbie Poster

I need to use a bool variable to detect if I'm in a word or not....and I'm writing a console program.

5ophie2012 17 Newbie Poster

Output to your code:

False
False
False
False
False
True
False
False
False
False
False

I have no clue what's going on...sorry. Here's all of the code I have in my program:

using System;
using System.IO;
class TEXT
{
    static StreamWriter writer;
    static StreamReader reader;
    static void Main()
    {

        int ch, characters = 0;
        int linecount = 0, wordcount = 0;
        

        // file that is being read in and displayed one character at a time in the console screen.
        reader = new StreamReader("../../../data.txt");
        
        // new file where hex characters will be written to.
        writer = new StreamWriter("../../../s_drcyphert.txt");
        

        do
        {
            //---------------------------------------
            // read one character at a time.
            ch = reader.Read();
            string x = (ch.ToString("x2")) + " ";
            bool status = false;

            //----------------------------------------
            // write each char to the console screen
            Console.Write((char)ch);
            //----------------------------------------

            // count the characters
            characters++;
            //--------------------------------------------------

            // create a method, WriteByte(). use parameters to pass in the character
            // to be written and a reference to the output file.
            WriteByte(x, ref writer);
            CountIt(x, ref linecount, ref wordcount, ref status);
            //---------------------------------------------------

        } while (!reader.EndOfStream);
        reader.Close();
        reader.Dispose();
        // print out all of the count information to the screen.
        Console.WriteLine("");
        Console.WriteLine("-------------------------------------------");
        Console.WriteLine("Number of characters: " + characters.ToString());
        Console.WriteLine("Number of lines: " + linecount);
        Console.WriteLine("Number of words: " + wordcount);
        writer.Close();
       
    }
    // method for counting the words and lines in the file.
    // to count lines, I used the ReadAllLines() method to keep track of how many lines …
5ophie2012 17 Newbie Poster

Have a look at my favorite Extension method from MSDN page.

I read about the Extension Methods....it was pretty interesting and could be helpful in the future for me. But my assignment calls for those specifics....sorry. That's why I'm limited to what I can do and I have no clue how to implement a bool and count words that way..my initial post explains.

5ophie2012 17 Newbie Poster

>Am I calling the method correctly?

Ok! but you can avoid the use of ref argument.

WriteByte(ch,writer);
....
....
void WriteByte(char ch,Writer writer)
{
   ....
}

Sorry....I already figured this one out. I passed the writer by reference so I didn't have to open the writer twice. It only took 1 line of code. lol

5ophie2012 17 Newbie Poster

To count words in a string use Split method and to count number of lines in a file use File.ReadAllLines() method.

linecount = System.IO.File.ReadAllLines(@"C:\file.ext").Length;

The method for counting lines will work in my case, but for counting words, I have to use a bool variable to keep track when I'm in a word or not. I'm passing that bool by reference, but I don't know what that bool statement should be or what I have to do within that method.

5ophie2012 17 Newbie Poster

OK, fine. But what has your assignment (which it obviously is) to do with a char to hex conversion?
If your problem about that is solved, mark it as such and start a new thread with your new questions.

Sorry about that, I started a new thread.

5ophie2012 17 Newbie Poster

I need to create a method that counts words and lines using specific guidelines and I can't figure it out:

Update the count of words & lines in the file as each character is read
create a void method, CountIt(), to count the lines and words
Parameters: pass in the character by value
pass in a reference to the word count
pass in a reference to the line count
pass in a reference to the bool that tracks if you are "in a word"
Will need a bool variable to keep track WHEN you are IN A WORD or NOT.

bool inWord = true;
int linecount = 0, wordcount = 0;
.
.
.
// calling the CountIt() method (which is in a loop)
CountIt(x, ref linecount, ref wordcount, ref inWord);
.
.
.
// the CountIt() method
private static void CountIt(string x, ref int linecount, ref int wordcount, ref bool inWord)
    {
 
    //count words and lines in here.    
 
    }

I have no clue how to go about this (what the bool should say, what should be in my method). I've been trying to teach myself through reading and other means but no luck.

5ophie2012 17 Newbie Poster

I need to create a method that counts words and lines using specific guidelines and I can't figure it out:

Update the count of words & lines in the file as each character is read
create a void method, CountIt(), to count the lines and words
Parameters: pass in the character by value
pass in a reference to the word count
pass in a reference to the line count
pass in a reference to the bool that tracks if you are "in a word"
Will need a bool variable to keep track WHEN you are IN A WORD or NOT

This is what I have:

bool inWord = true;
.
.
.
// calling the CountIt() method
CountIt(x, ref linecount, ref wordcount, ref inWord);
.
.
.
// the CountIt() method
private static void CountIt(string x, ref int linecount, ref int wordcount, ref bool inWord)
    {
    
    //count words and lines in here.    

    }

I have no clue how to go about this (what the bool should say, what should be in my method). I've been trying to teach myself through reading and other means but no luck.

5ophie2012 17 Newbie Poster

My program in a nutshell is reading a text file, outputting it to the console screen one character at a time, and then writing the characters as its read as hex pairs.
I'm calling this method in a loop: WriteByte((char)ch, ref writer); (passing in the character, and a reference to the output file, which is a StreamWriter)

Here is the method:

static void WriteByte(char w, ref StreamWriter writer)
    {
        
        writer.Write(w);
    }

I need to write the character to that output file as 2-digit hex, with a space in between each pair. How to I format the char to be a hex digit?

5ophie2012 17 Newbie Poster

For my assignment, I have to read a text file one character at a time and display it in the console. Here's my code for this:

class TEXT
{
    static StreamReader reader;
    static void Main()
    {

        int ch, characters = 0;

        // file that is being read in and displayed one character at a time in the console screen.
        reader = new StreamReader("../../../data.txt");
        StreamWriter writer;
        // new file where hex characters will be written to.
        writer = new StreamWriter("../../../s_drcyphert.txt");

        do
        {
            //---------------------------------------
            // read one character at a time.
            ch = reader.Read();
            //----------------------------------------
            // write each char to the console screen
            Console.Write((char)ch);
            //----------------------------------------
            // count the characters
            characters++;
            //--------------------------------------------------
            // create a method, WriteByte() for this task. use parameters to pass in the character
            // to be written and a reference to the output file.
            WriteByte(ch, ref writer);
            //---------------------------------------------------
           

        } while (!reader.EndOfStream);

I have to output the text that was read into a new file using StreamWriter, one character at a time, and I have to output it in hex characters (using the WriteByte() method). Am I calling the method correctly? And if so, what should that method look like and what should be in that method? I've been reading non-stop and can't seem to grasp the ideas.

5ophie2012 17 Newbie Poster

I still haven't figured out how to write the method CountIt()..... I need to be able to count words and lines...I know that i need a bool to check and see if it's on a character or white space in order to distinguish words, and a counter for both words and lines. I'm completely stumped. I commented as much as possible to aid anyone who can help me.
- White space can be ' ' and '\r'+'\n' and '\t'
- Lines are separated by '\r'+'\n' (0d 0a)

using System;
using System.IO;
class TEXT
{
   
    static void Main()
    {
        
        int ch, characters = 0;
        StreamReader reader;
        // file that is being read in and displayed one character at a time in the console screen.
        reader = new StreamReader("../../../data.txt");
        StreamWriter writer;
        // new file where hex characters will be written to.
        writer = new StreamWriter("../../../s_drcyphert.txt");
       
        
        
        do
        {
            // read one character at a time.
            ch = reader.Read();
            // write each char to the console screen
            Console.Write((char)ch);
            // count the characters
            characters++;
            // call the WriteByte() method to write the characters to the new file
            // one character at a time in hex characters (need help with parameters and
            // what needs to be in that method).
            WriteByte(ch.ToString("x2") + " ");
            
        } while (!reader.EndOfStream);

        reader.Close();
        reader.Dispose();
        Console.WriteLine(" ");
        Console.WriteLine(characters.ToString() + " characters");
        
    }

    static void WriteByte()// <<<< help with parameters??
    {
      // needs to write each charater to the new text file as hex.
      // parameters to pass in the …
5ophie2012 17 Newbie Poster

I've been working on it....this is what I have now:

using System;
using System.IO;
public class TEXT
{
    
    public static void Main()
    {
        
        int ch, characters = 0;
        StreamReader reader;
        reader = new StreamReader("../../../data.txt");
        
        do
        {
            ch = reader.Read();
            Console.Write(Convert.ToChar(ch));
            characters++;
            
        } while (!reader.EndOfStream);

        reader.Close();
        reader.Dispose();
        Console.WriteLine(" ");
        Console.WriteLine(characters.ToString() + " characters");
        WriteByte();
    }

    public static void WriteByte(string val)
    {
        StreamWriter writer;
        writer = new StreamWriter("../../../s_drcyphert.txt");
       // I need a loop in here..not sure how to go about it
        writer.Write(val + " ");

        writer.Close();
        writer.Dispose();
    }

    public static void CountIt(int x)
    {

    }



    


}

Still having trouble with the method AFTER reading the suggested material. I'm not sure if i should be passing through a string because you cant implicitly convert a char to a string...

Any suggestions?

5ophie2012 17 Newbie Poster

What you are reading in your code are in fact ASCII codes.
Change line 14 of your code into Console.Write((char)s); to see what I mean.
The cast to char is save I think, because it is a text file.
Have a look at this: http://msdn.microsoft.com/en-us/library/system.io.binaryreader.readbytes.aspx

Thanks for the help!
I was able to read the text file 1 character at a time and display it, and count the characters in that text file (which I had no trouble with).

Now what I'm having trouble with is taking that text file, and outputting it to another text file one character at a time in HEX with a space between each hex character pair.
This is what I have so far for that:

static void WriteByte()// <<< what parameters should I have in here?
    {
        StreamWriter writer;
        writer = new StreamWriter("../../../newfile.txt");

    }
5ophie2012 17 Newbie Poster

In line 13, if you are trying to read a char, why are you assigning it to an int?

Use string formating to output as hex (x.ToString("x2") for example).

You need to rethink the Counts method, as you aren't passing references or the character read at all.

I changed the int to a char on line 13 and it comes up as an error: Cannot convert type "int" to "char". An explicit conversion exists. (Are you missing a cast?)

And as for the Counts method, should I only have 1 parameter instead of 2 since I'm "passing in the character to be written and a reference to the output file"?

5ophie2012 17 Newbie Poster

Once again, I'm having trouble on my next assignment for class.

This is what I have to do:
Read and process a text file one character at a time:
1.) output the file to the screen one character at a time (as a char) as the file is read.

2.) output the file to another file called NEWFILE one
character at a time in HEX with a space between each hex character pair.
* create a method, WriteHex() for this task. use parameters to pass in the character
to be written and a reference to the output file.

3.) count each character, word & line in the file. characters can be counted in Main()
*create a method, Counts(), to count the lines and words and pass in the char,
and a reference parameter to the word and line count.

I have no idea how to even begin this.... I know I have to use the Read() method from the StreamReader class. Every time I go to output the text file as it's read using Read() method, it prints out a bunch of numbers. This is what I have so far:

using System;
using System.IO;
class TEXT
{
    static void Main()
    {
        StreamReader reader;
        reader = new StreamReader("../../../data.txt");


        do
        {
            int s = reader.Read();
            Console.WriteLine(s);
        
        
        } while (!reader.EndOfStream);
        reader.Close();
        reader.Dispose();
    
    }

    static void WriteHex(int x)
    {

    }

    static void Counts(int lines, int words)
    { 

    
    }

}

All help is …

5ophie2012 17 Newbie Poster

Hello!
I'm currently working on a program for class and I'm stuck. Here's the directions:

1.) Read one integer, n, from file: data.dat (the number "21" is in this file)
2.) The program (4 methods) will loop n times, using indexes 1 to n.
3.) Each time through the loop:
If the loop index is divisible by 3:
Call a function, three, that prints that number on a line
along with three "*" characters.
Pass the number to be printed as a pass-by-value parameter.

Else If the loop index is divisible by 5:
Call a function, five, that prints that number on a line with 5 "#" characters.
Pass the number to be printed as a pass-by-value parameter.

Else If the loop index is divisible by 3 AND by 5:
Call a function, both, that prints that number on a line n times.
Pass the number to be printed as a pass-by-value parameter.

Otherwise:
Print the number on the line.

Here's an example output:

1
2
3 ***
4
5 #####
6 ***
7
8
9 ***
10 #####
11
12 ***
13
14
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
16

Here's what i have so far:

using System;
using System.IO;
class FIZZ
{

    static void …
5ophie2012 17 Newbie Poster

Help! I'm developing a program for a class and I'm a bit lost. My program needs to do the following:
1.) Open a text file using a file dialog box.
2.) Loop and read the file one line at a time using Readline().
3.) Display every line which has text that matches user-supplied string(textbox input) using IndexOf.
4.) Display the location of the match including character # and line # until end of file.

Here's what I have so far. I'm able to open the file dialog, select a text file, loop through the text file until the end.

This is my "Open File" button:

private void btnOpenFile_Click(object sender, EventArgs e)
        {
            if (dlgFileSelect.ShowDialog() == DialogResult.OK)
            {
                reader = new StreamReader(dlgFileSelect.FileName);
                lblCurrentFile.Text = "Current File: " + dlgFileSelect.FileName;
                
                do
                {  
                    storedtext = reader.ReadLine();
                } 
                while (!reader.EndOfStream);
                
                reader.Close();
                reader.Dispose();

            }

        }

I have no clue what to put in my "Search" button method. I have attached a screen shot of what my interface looks like, and I'm using a listbox to display step #3 from above ^^

All feedback is appreciated, Thanks!