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

What?

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

My code (very few comments so far, sorry):

Why do people apologise for doing bad things rather than just doing what they know they should? :icon_confused:

My problem is this:
Every run of the program produces the same results. Same damage, same blocks, same double attacks, same winners, everything. I thought rand() was supposed to randomize the outcome in this situation? What am I doing wrong?

Not wanting to waste time looking through 400+ lines of code for that 1 wayward statement, all I can suggest without you being more specific is that srand() should only be called once at the beginning of the program.

If this doesn't help, give us a clue as to what to look at.

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

Is there something about CODE tags you don't understand? If not, you can either ask or read those words on the back of the input box for information.

The project states "Test it with a main program that takes as input an integer count followed by that many values." Where did you read an integer count? Doesn't getline() read a string, not a list of integers? You need to use a loop to read (and output) your numbers.

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

What about 'till (for until) and nothin'? If those are also valid then your condition might easily be simply to check if the apostrophe is adjacent to a letter on either the left or the right.

I suppose the OP is trying to remove apostrophes from sentences as in 'Here's an important string' and leave alone any that is found in sentences like "Don't do nothin' 'till I figure things out". In which case, according to your algorithm logic, the apostrophes in both sentences are in the same boat.

In my opinion, maybe we should help the OP do what they've been asked and not overly complicate the problem. There's always more stuff to consider, but at the learning stage, one level of complication should be enough to start with. :icon_wink:

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

So far the background has never cleared for me.

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

What I'd do is program one step at a time. Using your last description,

Start by writing an empty main() Then write "1. a void function to read in the three test scores and pass them back to main as reference parameters." Test this by outputting the parameters after the return to main() . Get it working before moving on.

Next, add "2. a double function that is passed on the parameter list the three test scores, computes the average and returns the average as the value of the double function." Test until ready in the same way.

etc....
Just take your programs a step at a time. Slow and easy,

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

And:

3. Increase the value of variable x by variable y
x= x+y;

There's another way to do this. Look at double operators.

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

thanks...
the program will show the output that i attach in thread.
one more, i don't familiar with this site. so pliss help me to enjoy with this site.... tq..

To enjoy this site, read the following:
Read Me: Read This Before Posting
Code Tags
The Rules

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
else //c is a single quote
            {
                //How do I make the single quote be counted if there is an
                //alphabetic character to the left and to the right of it?
            }

Probably you want to set a flag that says "I have a quote".
And you have to remember the previous character so you can check it.
Then when you read the next character, you need to check everything and output the quote if necessary before outputting the next character.

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

Hey man, you don't have to make a trivial comment to EVERY thread

You mean like that one? :icon_twisted:

iamthwee commented: And this one Mr Disney? -2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And I need real time programming with millisecond accuracy, which Microsift has taken away.

M$ hasn't taken it away. It was never in Standard C in the first place so it was compiler dependent. I believe there is an API to handle what you want, which means it would be available in most any language on Windows, since it's part of the OS. Check http://msdn.com

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

Read the last line of my post, please.

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

Where's your C++ case reserved word?

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

Recursion means you call the function until you get to a specific condition. In this case, you might want to call the function again with n-1. Then when you get to the n==1 you start returning and add all the values returned to get the value.

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

I am sorry for my poor English.
Please excuse me for that.

We have no problem with poor English as long as you try to make yourself understood. I was hoping you'd try to explain again what you said before. Since you didn't, I'll attempt to help based on what I think you want.

Now, can i have some advices on how to code this loop.

Make an array of 12 values to represent the number of days in each month. Then you use the for loop to add these values to a variable that will contain the number of days from one date to the next.

Be sure to read the post at the top of the forum titled Read Me: Read This Before Posting.

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

Hello,my freinds:

I'm writing a program with Qt4.The program can communicate with each other in a LAN.
Now,may ererything be ok,but the constructor is wrong,the compiler tells the fallowing:

  1. main.cpp:4: error: new types may not be defined in a return type
  2. main.cpp:4: note: (perhaps a semicolon is missing after the definition of ‘Pigeon’)
  3. main.cpp:4: error: two or more data types in declaration of ‘main’

My Pigeon.cpp file includes the following sentences that implemente the constructor.

Well, since the error is in main() on line 4, maybe looking there will help.

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

but people you aren't focusing on the task at hand!! I need help with my function taxAmount!

Sorry.

great!! I didn't think that would have mattered but I got everything working! NOW I just need help with the function taxAmount calculation!

Ahh, that's why. Help with what? Details, please...

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

ok that problem is solved. what i should't of done was put<<endl; at the end.

i am stuck at this new problem.

here is my problem: the user input a started date for a year, and let said Jan and a year 2000. so Jan 1 2000 started on sunday and ends on monday.

Actually, your problem is English. "user input a started date for a year" is hard to decipher. And "let said Jan and a year 2000" is undecipherable.

"so Jan 1 2000 started on sunday and ends on monday" is completely untrue. 1-Jan-00 was a Saturday. To start on Sunday and end on Monday there could only be 30 days in the month. Did you actually look at a calendar?

how do i do a loop so it will calculated the correct start date for any given month follows?
so

for (month=1; month <inputMonth; month++) maybe? Or something like that...

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

No, you haven't tried everything. You haven't tried one suggestion nor answered one question I posted. Can't help you if you don't care enough to explain your thinking or think about suggestions given.

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

my code is actually a long around 500 lines.
so putting all lines of code is not a gud idea here.
suggest me wr i put my codes so that you can have a look on it. and can provide needy solution to me.

So add output statements to watch the program flow and try to pinpoint th problem area. Then you can post the code that shows the problem.

And what's gud and wr? Please see this.

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

The basic flow of the program is not that complicated. You kept it simple enough. There are a few details, though....

First thing I notice is fscanf(fin,"%c", txt[j][i]); Using fscanf() to read a character is like opening your front door with C4. It works, but wouldn't a key be better? Use fgetc() . It's designed to read a character, and only a character.
Same with fprintf(fout,"%s",text); . How about fputc() ?

Instead of a double loop for input, use a single loop and use fgets() to read a line at a time. This way the BASIC file doesn't have to have SPACE-filled lines. Increase each line from 80 to 82 to take into account the trailing '\n' and '\0'.

In this code:

int main(void){
    FILE *fout, *fin;
    char filename[50], spare[MAX_COLUMNS], str[MAX_ROWS][MAX_COLUMNS];

    for(int y=0; y<=MAX_ROWS; ++y){
        int z=y-1;
        fgets(str, sizeof str, stdin);

what are you reading? Where's the prompt so someone knows what to enter? if(str[y][1]<=9 && str[y][1]>=0 ) You just read a characters. There are no numbers, they are characters. You need at least if(str[y][1]<='9' && str[y][1]>='0' ) But then, you could also just use: if(isdigit(str[y][1]) and get the same result. And why str[y][1]? Don't arrays start at str[y][0]?

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

Hi,
I've wrote all code using using matrices and the problem happens even more often.

So rather than fix it, you took out what you were supposed to learn?

I've tried it in another compiler (DEV-C++) and with this one program just doesn't run.

That should tell you something. The code is very wrong. What happens with Dev? Crashes? Doesn't compile?

Start over and slow. Write a small piece of the code, compile, test. Then add the next step, compile, test. Repeat until the program is finished...

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

It works either way, but putting the proto in the function IMO just clutters up the function.

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

>Outputting a bunch of newlines '\n' is the only portable way.
It's portable only in that you're using standard code. It's not portable in that you don't know how many newlines to print, and if the stream is redirected (or never wrote to a screen in the first place), you're not going to be clearing any screens. "Clearing the screen" requires a screen and knowledge about that screen, both of which are fundamentally non-portable.

Yes, I realize that. but for someone learning \n's are as simple and portable as we have.

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

Ok, is this what you were thinking?

No. Get rid of the char* and just use string . It'll make the code simpler. The problems I see so far:

char *entireString = new char[0];    // this defines a char string with no characters

entireString[line.length()+1];    // what are you expecting these statements to do?
keys[line.length()+1];
values[line.length()+1];

strcpy(entireString,line.c_str());  // don't need this at all, plus you just screwed up your memory
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

ohk going back to my code with count...
in that too while(fin) is running endlessly...can you tell me the reason why?...
thanx in advance...

I just did.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
while(fin)
  {
    ch=fin.get();
    fout.put(ch);
    
    while(ch==' ')
       ch=fin.get(); //*****

  }

If the last character in the file is a space, your inner loop will run forever because ch is never changed but the fin.get() has returned an error which you never test for.

Go back to your other code with count . It should work. This code will skip each character that follows a space. And make sure you always test for an error from all of your your inputs.

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

If count is 0, the space is written. count is then incremented. If another space is immediately read, it is not written because count is no longer 0. He has effectively removed extra spaces as his original post describes:

i have made a program on text file to remove extra blank spaces in a file but it is not working correctly.

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

You don't need c_strings. Just look for the two characters that begin and end a value you want moved and use the substr() method to move the value.

And why are you indenting 3 miles? Too much indenting is almost as bad as no indenting. 4 spaces is enough for any indent.

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

Also, every line that has the word count on it needs to be deleted. It is preventing those spaces from disappearing.

count is used to delete extra spaces. Removing them will prevent spaces from being deleted.

[EDIT]
WaltP you missed the fil ifstream at the bottom... so he actually should see more output on the screen...

No, I missed the cout at the end. But miss something I did...

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

Nothing else is output to the screen. What do you expect to happen? If you think there's a problem, add a few cout statements to follow what's happening and pinpoint the problem.

And isn't this a C++ program? Why are you using the extremely dangerous C function gets() when there are perfectly good C++ input functions available?

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

Clarify: only needed when input is an integer, not a string. With integer input you can not enter the format "dd-mm-yyyy" because it won't accept the hyphens. You have to use string input for that.

Well, with the posted code

if(m==2) //FEBRUARY
    {
       if ((y%400==0) || (y%100==0) || (y%4==0)) //LEAP YEAR
       {
          if( (d<1) || (d>29) || (y<1875) || (y>2199) ) //VALIDATION
          {
          z=z+1;
          }
       }
       else // NO LEAP YEAR
       {
          if ( (d<1) || (d>28) || (y<1875) || (y>2199) ) //VALIDATION
          {
          z=z+1;
          }
       }
    }

I figured the % operator would be usable. :icon_wink:

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

And please learn to format your code! It's impossible to follow.

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

Divide by 10 and use % again.

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

First of all, how about variables named day, month, and year instead of 1 letter cryptic names. And what is z for? Are you sure your date validation works?

Look up the % operator to get the individual digits of each value so you can add them up. There are many threads here that show how to do this. Search for modulus operator.

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

EXTERN simply defines the variable to be accessible from a another source file. Add the EXTERN statement in a local header file and define the variable in only one of the source files.

For example, in the error.c source file you might define int errCode = 0; In error.h you define extern int errCode; and #include this file in each source you need the errCode variable.

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

>How do you clear the console screen without any system-compatibility issues?
Start by altering reality such that standard C++ recognizes a "screen" and a "console" in a convenient way.

In other words, brute force. Outputting a bunch of newlines '\n' is the only portable way.

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

There were a couple of style changes today so I want to mention them ...
Firstly, the [inlinecode] tag has been replaced with [icode] to make it easier / quicker to type.

Excellent!!!!

The watermark behind the editor indicating to use code tags (programming forums) and not to solicit or plug (internet marketing forums) now only shows up with the standard editor mode and not in wysiwyg editor mode. Additionally, it disappears once you click on the editor window.

Nice, although is hasn't cleared for me. And if it's going to clear, can you make it darker so it's really noticable?

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

After testing the code i did come with the final result i wanted thanks to Duoas. Now my question is, how do i set it so i make an array that i do not know how big it will be since the user will input the info. in other words i have it set currently to a constant of 30 but im not sure how many words the user will use. and because i have it set to 30 there will be 30 loops which that may be too much or too little.

Since you don't know how many characters a user might enter, you just have to make the array large enough to hold a maximum they might enter. Keep in mind, though, whatever you define, some jerk just might enter too many characters.

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

1) Calculate the number of days to Sept 1, add the day of the week for Jan 1, divide by 7. Remainder should be the day of the week for Sept 1

2) Line 46 of your validation function should be < not ==. IOW, how are we supposed to know? we ain't psychic! :icon_wink:

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

You can't possibly get 155.419 from an unsigned long, there is no decimal point from integers. You need float or double.

And dividing two integers always gives an integer, even if you load it into a floating point number. For example:

double dval;
dval = 25/2;

12.000 is loaded into dval, not 12.5.

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

The idea of this forum is to post the code here (properly please) and we all get a chance to help you. Be sure to read this first

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

I can't see how this code does anything. You have 3 nested while loops all exiting on the same condition. And if you read this you'll see your condition is wrong ( feof() is the same as .eof() )

Then in the second loop, you read a single character and output it. Other than that, no other output of note.

If you happen to find the input string in the file, why do you reread the file?

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

Count each number you output. After every 6th number, output a newline (\n)

Use the % operator.

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

it should be if the user hits either the Q or q then exit the loop., but when I was using the or, it would not exit the loop.

Yes, but this statement is "if == " not "if !=" which is what you were using in the code.

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

Not a clue what you are asking, and your code is too hard to read. Try formatting the code using this info so we can follow what you're trying to do.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Make a loop that exits when your value is zero
In the loop, 
    calculate the modulo-10 of the value using % (get the ones digit)
    output the digit
    divide the number by 10
endloop

That's basically it.

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

chalasesha, you obviously need to read my links, too. As well as this.

And why would someone be satisfied with a program you wrote? What could they possibly learn by handing in your work?Especially poor and non standard code.

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

Please format your code. It's really hard to follow.