WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Are you absolutely sure the file opens correctly? You need to test the return value of the file open to make sure it's really open.

Can you guarantee that there are exactly 8 values in the file? What if there are only 7? Or 10? You should probably loop, reading 1 number at a time while watching for EOF, and adding the numbers to an array instead of individual values.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

wow, i could change my name and my picture and i would be like a completely new person that no one would know who i am!

An episode of the original Star Trek immediately pops into mind...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

After you read the last number, you still have the end-of-line in the file. here's where getline() can clean up the EOL. Since you didn't describe in detail what's really happening with the second line, that's my guess.

But using getline() to read each line and parsing the line is still the better solution.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Start by describing how you can tell if a number is prime.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I think you should start over and concentrate on only the input. Think about how you need to loop and display your values at every point. Once you get the the end of the the file, output your matrix and make sure it's right.

Then, and only then, move to the next task.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

We need to get some better information.

You've been bouncing all over this program for 4 pages and still don't have your file input working right yet? In your first post you say

The main problem i am having is the storing the file character by character into the 3D array.

Your last post (#32) says:

i want to input the text file, character by character, in the array but i seem to be getting, problems...

After all this help, why is your input not working yet? Haven't we been helpful at all? Ignore everything else and get your input working!

Another problem is this -- you say (again)

i want to input the text file, character by character, in the array but i seem to be getting, problems...

Do you need more help with your problems? If so, do you think describing the problems might be beneficial?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hey everyone here are my updated errors, and code, i have gotten them down too three now

Errors:
1>assign10.cpp(273) : error C2065: 'Start' : undeclared identifier
1>assign10.cpp(274) : error C2065: 'Start' : undeclared identifier
1>assign10.cpp(275) : error C2065: 'Start' : undeclared identifier

break the error down into pieces:
Start -- must be something wrong with it
undeclared -- what does this word mean?
identifier -- what about this word?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hey there guys,

First time poster here, so I apologize for being a rookie.

Then you should have been posting for the past year. Then you wouldn't be a rookie :icon_mrgreen:

This is my first VB class and im having a hard time with For-Next loops.

As you can see it is only an issue of having the maximum number of stars on top, rather than at the bottom. I figure the issue is just reworking the loop, or adding another nested loop, but I am having a hard time finding the solution.

You aren't having a hard time. you're second-guessing yourself. You already know the answer (bolded above).

You need one loop for each line. Within that loop you need another loop for each '*' on that line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

sl is a string class, and strcmp() works only on char*.

Use the string class for owner and pass and you can simply use == to do the compare.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

There were 3 solutions posted. The last one is the best. Just C++ it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Go back to this code:

char cabin[3][4][13]={' '};
    char ch, res;
    int num, lvl=0, row=0, col=0;
    
    for(int a=0; a<3; a++)//Levels
      {
       for(int b=0; b<13; b++)//Rows
       {
        for(int c=0; c<4; c++)//Colunms
        {
            cabin[a][b][c] = '*';
        }
       }
      }

and fix your indecies and loops. They must match, and yours do not. You have an abc confusion going on...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Are you sure you're reading the file correctly? What are you doing with the data?

Where did you initialize the cabin matrix? When you define a variable, if you don't initialize it they contain garbage values.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

That looks good....

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I changed the header file name?but it still gives me the same mistake,like unidentified reference...

In non-English speaking countries, do they actually teach you that spaces after ?,.: etc are not necessary? If so, they were wrong. Always add a space before you start a new sentence.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i changed the array and the output is still the same. (random symbols). Also i thought that array[3] had 4 memory slots. so that is why i had the array number set to 1 less then wat i needed

Why would array[3] have 4 slots? It only has 3, as the number signifies -- array[0] to array[2]

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please learn for FORMAT your code. It is very difficult to read, and if we can't read it, most of us will skip your posts.

Wouldn't it be better to print the average after it's calculated rather than just before?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Variable names are case sensitive, but file names are not.
#include <IoStream> would work just as well.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The problem doesn't occur until the comparison between the user's sequence and the generated sequence.

do
         {
             a = 0;
             for(b = 0; b <= 5; b++)
             {
                  srand ( time(NULL) );
                  lotto[b] = rand() % 53 + 1;
             }          
             
             for(b = 0; b <= 5; b++)
             {
                   if(ticket[b] != lotto[b])
                   {
                          a = 1;
                   }
             }
         
             c++;
             cout << c <<endl;
                 
         } while (a == 1);

srand() should only be called once. Move it to the beginning of main() .

Is it not possible to compare arrays this way? What happens is the loop continues without stop, I realize it should take some time but 6.5 million iterations is unreasonable. Any suggestions?

You are dealing with random numbers, aren't you? There is never a guarantee using random values that a specific sequence of 6 numbers will occur. There are probabilities of the occurrence, but no guarantees.

What is the probability of a specific 6-number sequence occurring?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Here's what Lerner was referring to on line 26 -- feof() and .eof() are identical.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You can have your username changed. Post the name you want.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I have found my self replying to threads that are weeks old. I could edit the post but would removing all the text remove my post?

If you made a descent reply, then why want to delete it?

And if you didn't make a decent reply, why not? :icon_mrgreen:
or
If your reply did descend, pick it up and try harder :icon_twisted:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In your code:
The union uses OR
The intersection uses AND
I believe you'll find the difference uses XOR

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Are you having a problem you're not telling us or just asking a strange question that's hard to decipher?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am running into multiple issues. I am not exactly sure how to go about rolling the dice,

Call rand() -- the value returned is one die roll.

summing them together,

Start with a value set to 0 as a total. Add the rolled die to it.

and how all the loops will work together for the desired output.

Think. Write the ideas on paper.
** Get one die (the computer only rolls 1 at a time).
** Roll it to the specifications of possible input
** -- 3 dice - 3 rolls;
** -- # rolls to check - 10 - repeat above 10 times. You don't want to try 10,000
** Write down each and every detail of how you are getting to an answer. When you understand that, you're ready to start coding.

Once again I am new to all of this.

Duh, ya think? :icon_wink: If you're having a hard time with simple tasks, you're new. That's OK. We all were once. No need to remind everyone.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since you are writing a student project on rolling dice, not solving universal chaos theory, rand() is more than adequate.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please decipher this statement as it pertains to coding:

You need different index values because you are removing characters so the indices will not be identical once punctuation is found.

What is an index value?
What are indices?
Pertaining to the program you wrote, how did you 'remove punctuation'?
Anything else you can explain?

I'm asking because in programming you must figure this stuff out. These are very simple (you will agree in another week, believe me) ideas.

Try doing this on paper. Write down your sentence. Copy each valid character one at a time and keep track of the character position in each sentence. When you understand the technique on paper, how do you tell the computer to do exactly what you just did? After all, you are a computer too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Who's/which idea did you use? It doesn't look like any of our suggestions.

If it was jonsca's, your arrays are equal in size and he distinctly said

You know the new array will be less than or equal to the old one in size.

You need different index values because you are removing characters so the indices will not be identical once punctuation is found.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Easy way:
Copy the string a character at a time into another string in a loop. Don't copy the punctuation.

Harder way:
Set up two indices, one (indOrig) for pointing at the original string, one (indNew) for pointing at the new character position. Both start at 0.

During your loop,
1) copy the character from the indOrig position to the indNew position.
2) increment indNew for every non-punctuation character.
3) increment indOrig for every character.
Be sure you loop far enough to copy the trailing \0

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Other than c being use to accept input and count the number of 'c's, I seen nothing wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I created the program to obtain input from a user instead. The program compiles, but when I run it, it get stuck at the function call in my while loop in main. I can't seem to figure out what's wrong with my function?

Since we can't see your screen, "it get stuck" is too vague. If you give us details for complete understanding, you wouldn't have to wait hours for a fix.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Did you actually try to read the first 4 numbers on one line? That wold be your first job. Just try something. If it doesn't work, we can help. If it does, you don't need us, nor the big wait time (1.5 hours for this one) waiting for an answer.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

alphabet from lower to upper , using ascii
what logic should be use to convert small letters into capital using ascii codes??
for example ascci code for A is 65 and ascii code for a is 97
how can i coonvert from integers to character ?

Such confusing responses....

What is the difference (numerically) between 'A' and 'a'?
What about 'B' and 'b'?
'C' and 'c'?
Notice a pattern?

Therein lies your logic for conversion.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You do know you can say s[0], s[1], s[n] to get the characters of a string, don't you?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

:D When you post answers to questions here do people jump down your throat about using bad techniques, commands, formatting? :twisted:
that would be clue #1...:icon_mrgreen:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So don't start your loop with your first value :icon_rolleyes:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not even going to try reading that badly formatted code. Do instructors really teach that indenting 30 characters is a good thing?

Try this information

I just happen to notice this, too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So what's wrong? The program description doesn't make sense, but the code has only 1 minor error -- the for statement is a little off.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

IT doesn't enter second loop don't know why. Any suggestion?

Yep.
Split for(int k=0; k<getphraselength(); k++) into 2 statements. What call the function every time you go through the loop? Make it:

len = getphraselength();
for(int k=0; k<len; k++)

Now you can display len and see if the value lets the loop run.

In general, don't call functions in the parameters of the for if you can help it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Open the file with "wb". "w" is text by default.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Dear Friend,

But are you getting my point or not? As i want to see entire output on my screen. How it will be possible, that i want to know. Even if with DOS prompt i am getting same thing.

Can anybody help..?

Thanks and regards

Get a new monitor that has 255 lines on it.

Or remove the \n from the printf() line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

is this

if (buf == "TIME") {
    printf("Time: '%s'\n",msg);
}

the proper way to compare strings in C?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

WaltP: please don't put words into my posts that aren't there. I'm saying no such thing. My comments were intended for Jay.

Such as? Only thing we have a disagreement on is Random being a reserved word. It isn't.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Same crap. Except you added it in TWO places this time. As long as count < size, the loop will never exit. What cold possibly cause that in you new and improved code?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
[B]random[/B]   Macro that returns an integer.
 Syntax:
   random(num);
   int random(int num);

Not every compiler may have this, but some do.

Sorry, that doesn't cut it. If not all compilers (only TurboC as far as I can tell) have it, it is not a reserved word. And any use as a variable will override the macro definition.

Or are you also implying that when using DevC I can't create a variable named clrscr or gotoxy because it's defined in TurboC3?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You'll really have to scan the file for the line. There's no telling where any specific lines start.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

:icon_rolleyes:
Now you're getting really heavy into "I'm not going the think anymore, I'll just let them tell me what to do."

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
if (game_board[row_coord][col_coord] == '~')

If this is true, count is never incremented.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then you did it wrong. But my psychic powers aren't working today so I can't tell why.

churni commented: thanks for the help - you really are a genius in my eyes! +1