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

I have no idea what you are trying to do. A better or more detailed example is needed.

My bad english!

You don't say! :icon_wink:
We can get over that...

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

At the very beginning of the program, open a file names XXX.XXX for writing. Write something (anything) into it. Close the file.

Now search for the file XXX.XXX on disk. When you find it, that is where your input file must be. Move it there.

Delete that new code and try again.

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

Look through the input string a character at a time. For anything that's a letter, display the letter and ask the user to enter a value.

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

Take it a step at a time.

Initially, forget the class itself.

How would you represent a Bigint value? As a long? As an array? What makes the most sense for 20 digits?
Conceptually, how would you do an operation on this value?
Now write an input and output function to test this design idea (with no operations, just I/O). Compile and test it. Does it work? Does it make sense?

Once that's done, how would you add two values? Write it and test it.

If that works, now write your class with these tests in mind. Input and Output first. Test. When it works, drop in the ADD operator. Test.

Continue from there...

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

I did. It was crap.

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

You can't do an addition and xor at the same time

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

What is %if in your format?

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 depends a lot on how you have the data designed and a host of other stuff. Details are necessary.

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

If you output important values at key locations in your code during debugging, most questions like this could either
1) be answered without waiting 2 hours for a replay on a forum
or
2) give important information that can be posted here if the answer eludes you.

Also, why are you changing the value rather than the mask when you are checking the bits?

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

Suppose you read the Member Rules.

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

If you start your mask as unsigned displayMask = 1 << 31; , what is reverse after executing reverse <<= 1 ; ?

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

HI ALL. I'M LOOKING FOR A SOLUTION FOR MY CODE. I WANT TO FIND THE HIGHEST CHARGE AFTER AN ARRAY HAS SHOWN UP(SPEAKER'S FEE). WHAT CAN I DO??
THANKS

HERE'S MY CODE:

First: STOP SHOUTING!!!! It's very rude
Second: Use CODE tags! Descriptions are all over this site.
Third: Explain the problem.

Start by setting the HighestCharge variable to the first speaker's value. Then test each subsequent fee and modify HighestCharge accordingly.

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

Once you enter a function the size of the array is lost since the array address is passed, not the entire array.

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

How would I loop a switch statement until one of the valid options are entered.

would this work?

It will work fine if you set up the while condition correctly. Your condition is always TRUE.

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

If the file contains a letter,number why are you reading 2 integers? Don't you need to read a character and integer?

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

Showing that the data still has a newline in it.

Want it gone, also?

for(i = 0; i < strlen(YourString); i++) {
  if(YourString[i] == '\n') {
   for(j = i; j < strlen(YourString)-1; j++)  //shift down all char's above i
     Yourstring[j] = Yourstring[j+1];
}

That should do it.

Wouldn't it be simpler to use:

ln = strlen(Yourstring) - 1;
if (Yourstring[ln] == '\n') Yourstring[ln--] = '\0';

since the '\n' is at the end of the string? Saves two loops.

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

... Sweden, Germany, BeNeLux, etc.

Isn't BeNeLux a vacuum cleaner? :icon_twisted:

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

That is perfectly legal. For example:

cout << "This " <<
        "is " <<
        "a " <<
        "valid " <<
        "statement " <<
        endl;

Whitespace is ignored, so \n, SPACE, and TAB can be used most anywhere.

[EDIT]
Looked at your post again and missed the #define.... You're right. But if the line ends in \ it's OK:

#define O cout << "This " << \
        "is " << \
        "a " << \
        "valid " << \
        "statement " << \
        endl;

[EDIT]

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

I would guess your problem is with the << and & operators.

<< is the bit shift operator
& is the AND operator

With that you should be able to look them up and figure the statements out.

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

Then just put the system("cls"); command immediately before the new menu is displayed.

We usually don't recommend doing things like this though because there is no standard way to clear the screen. It's different for each O/S.

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

Look for memory leaks. You may be running out of memory.

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

Could you please give us an example of what you want rather than half an explanation using strange code?

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

You've made a Windows program instead of a Console application.

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

itoa() is not a standard function and may not exist in your compiler.

And strtodnvert() doesn't seem to exist in Google at all.

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

If you try to fail, and succeed, which have you done?

Don't know, but it might have something to do with a play called "Springtime for Hitler" :icon_mrgreen:

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

Roman numerals don't have decimals. It's therefore undefined so you can pretty much do whatever you want.

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

yes i need to find multiple keys. So i should read them into differnt variables then instead of an array

An array would work fine.

What happened to the array? It would certainly make it easier now that you've added almost enough information for us to understand what you're doing. Almost...

Set up a nested loop. Outside loop can go through each value, inside loop can go through each key.

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

You should be checking for EOF during read. Look up your read function to see how EOF works.

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

ok this is what i have so far. amd as for the return statements. Our teacher dosnt want us to keep runnign the program if we cant open the file.

I see you don't believe me at all. As an experiment, change exit(1); to return 1; and see if the program continues if the file doesn't exist.

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

What happens when you read a blank line and try to tokenize nothing?
How can you tell the blank line is read?
How is it different from the other lines?

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

yes i need to find multiple keys. So i should read them into differnt variables then instead of an array

An array would work fine. You said "a variable" first, not "an array". They are different.

and the exitis b/c we havnt learned anything else yet

You haven't learned the return statement yet? What's that at the bottom of your main then? return does the same thing no matter where it is in main()

and the cin.get i guess i can use

Much better...

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

Ok what I need to do is utilize a binary search algorithm and determine the index location of a set of keys.
The keys are in the file the user enters along with the numbers that have to be searched through. But im lost on how to do this. Do i need to put each key in its own variable?

Do you need to find multiple keys? Can you stuff multiple keys into 1 variable? How?

#include <stdio.h>				    // Need for getchar

Why? Can't you use cin.get or something similar? Why use a C function when writing C++?

#include <cstdlib>					// Needed for exit function

Why? Do you call the exit() function when you can simply say return 0; as is the norm?

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

fgets() will read up to BUFFER-1 characters or up to and including the '\n' in a line, whichever is smaller. So if your file contains ABCDEFG and BUFFER is 6 you will have in your input ABCDE\0 or ABCDEFG and BUFFER is 10 you will have in your input ABCDEFG\n\0 Remember the \n on input (file or keyboard) is a real character, not a vacuous indicator that does stuff.

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

A couple things,
1) Get rid of the system("CLS") . It's in your way, you can't see what's happening. If you really need them for your instructor, add them later, otherwise don't use them at all.

2) Look carefully at what your stationsswitch() function is returning.

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

Hello. I am asking for help. I have 2 input files containing sorted integers. These 2 have to be concatenated into a third file and now all the integers must be sorted. (Example: file1 contains 1 5 8, file2 - 2 3 6 and file3 must contain 1 2 3 5 6 8 ). How can this be accomplished? Thanks in advance. Here's what I have done so far:

A concatenation would result in 1 5 8 2 3 6 whereas what you want is a merge. Merge sort is not necessary.

Read value from file 1 (X1)
Read value from file 2 (X2)
LOOP until an EOF is reached
    if X1 < X2
        Write X1
        Read another X1
    else
        Write X2
        Read another X2
    endif

Once you have an EOF condition, you need to decide what additional code you will need. There is more...

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

What do you tip a cow? 18%?

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

If each record is terminated by '%', why are you testing the first character of the line read?

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

If your input statement requires a number (double or int) you cannot enter a '?'.

You need to input a string, test the data for '?' or number. If number, translate it from string to value.