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

Same way

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

Just use it. The compiler will compensate for you.

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

First, format your code so we can follow it. That is necessary if you need others to read your code.

If you aren't sure if you are correct for 2, 3, & 4, try running the program. That will tell you whether you are correct or not.

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

I also have a warnings in double windchill, double avgairspeed, and double avgtemp which say that "control reaches end of non-void function." I don't know what that means.

The functions are defined as double, therefore need to return a double at the end of the function.

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

What part of non-portable is difficult to understand?

I don't understand what your talking about.
I need something like _getch(); using just the standard libraries(or less). And no Operating System specific libraries/headers.

Clear and succinctly:

There is nothing, repeat nothing like getch() that is
1) portable
2) not O/S specific
3) not compiler specific
4) standard
in C++ NOTHING. Period.

sergent commented: . +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The assignment is to make a program that can read data from a file and give out the wind chill, average temperature, average air speed, and average wind chill. It must also reject data that has a temperature (in fahrenheit) of larger than 50 or an air speed of larger the 120 mph.

Good assignment.

I haven't even written any function to calculate the average wind chill because I simply do not know how.

That makes it very difficult to program anything.

There are definitely problems here, but I don't know how to correct or solve them.

Neither can we. You didn't bother telling us anything about them. All you did was say "here's my code -- fix it" which is not our thing. You need to say "one problem I have is (details of what's wrong and where). Another problem is (details of what and where)."

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

Guys, making post after post after post is not the correct way to deal with a forum. Think about your post before you type it in. If you need to add something, EDIT the post, don't just make another post.

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

Now, how to figure 3.75 degrees.

Easy. Draw a circle. Take away everything that isn't 3.75 degrees.

Nick Evan commented: indeed +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

>> Basically, because you didn't call it properly, you've unintentionally overloaded the function, but you don't have a definition/implementation of the overloaded version.
i think you'r wrong about that, you cant declare a function as this

b.getLeafCount();

you must use :: operator to tell the compiler that it belongs to a class, not the '.' operator

No, he's completely right. b.getLeafCount(); is not a declaration. It's a call to the getLeafCount(); method in the class named b. If he had used BinaryTree::getLeafCount() in the correct place in the code, he would have an overloaded function.

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

Since you can't pass a character array as a return value, pass the emptycorrectAnswers[] array into the function rather than defining it in the function.

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

The conditions that i want to add in the loop is as follows :

(sentence[type] == 'Z' ) putchar ('A');
(sentence[type] == 'z' ) putchar ('a');
(sentence[type] == ' ' ) putchar (' ');

the problem is that i don't wana use the if else if loop in that.so how can i integrate these conditions in the for loop

Use regular IF statements within the loop.

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

Out of all that information above, not one question was asked, not one problem you have was mentioned. Since we aren't "The Psychic Programmers Network (R)" we have nothing to look for. Try adding details you want answered.

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

I see two things immediately.
1) Prime numbers are integers, not doubles. 24.5 does not have prime values. This will make your code easier to deal with.
2) Your formatting makes the code very difficult to follow. If you want others to read your code, make it easy for them and format it.

When you repost your formatted code, add comments to explain what you are doing and why. That helps us understand your thought processes.

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

%p = Pointer; address format
arr+3 = arr[3] -- just two different ways to access the 4th array element

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

I'm having trouble figuring out why my program has stopped after 20 moves.

Looks like you decrement squaresLeft even when the square you test has already been used.

Also I am not sure how to keep all moves on the board itself.

Test. After adding vertical[] and horizontal[] to your location, test to see if it's on the board.

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

Whoa! 25%? 10% wouldn't necessarily be significant but 25 doesn't seem to be chance. So what's the next step to see if it wasn't just an anomaly?

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

Well, the test is over, and unfortunately I was very disappointed in the results. There seemed to be no increase in user activity on the site at all without the ads.

I'm curious as to why you feel a single day test would show different user activity. Who would have been aware of the "Ad Freedom Day" so they could log on and enjoy no ads? And how many new users would be enticed for one day? No ads would do nothing for the users in a single-day test.

IMO, all you tested was your backend timings and such.

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

when i run the program, just "mahasiswa 5" that appears, how to make it show "mahasiswa 1" until "mahasiswa 5"

Put the print statement in a loop.

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

Lots of great pics here can be turned into wallpapers.

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

strcmp()

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

I'm writing a reverse Polish calculator. If the input is 1 2 - 4 5 + *, the output should be 9, but I'm getting -9.

[u]1 2 -[/u]  [u]4 5 +[/u]  [u]*[/u]
   1-2    4+5
   [u]-1      9    *[/u]
        -1 * 9
          -9

Looks right to me.

minimi commented: Thanks! +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When you enter your code,
1) how many keys to you actually press?
2) how many characters, therefore, are in the input buffer?
3) what are they?
4) how many characters does the code = getchar() retrieve?
5) are there any characters left in the buffer? If so, what?

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

Look up the format of printf(). Use that info to do your conversion.

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

How do I check for this? The program is never getting back into the main(), after arrange(). I am thinking that you may be correct. How do I check for this error, and fix it?

Start outputting useful information, like index values and other variables that, if wrong, can cause problems. Like if i>14 for example.

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

How would you do it on paper? What are the exact steps? Write the steps down. If that doesn't help completely, ask specific questions about the steps.

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

The issue is that I need to end the program when "control Z" is typed by the user...

Read up on the scanf() function and see if it returns a value. That may give you a major clue on what to do.

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

I get the cout statement of "end". Then the complier/runner whatever flakes out and I get a windows message that says the program I am running has stopped working unexpectedly. I click okay then at the bottom of the output I get, this process returned thing. Why is this happening?

"complier/runner whatever" -- try program... That's what you are writing.

Outputting end shows it finished the function and returned. So the problem may be after arrange() returns. That is unless arrange() wrote over memory it shouldn't have. Also, what happens if one of your holder.substr(); calls returns an error/not found?

When outputting trace messages like you are doing, follow these steps:
1) Add the name of the function to the message so you can trace the actual flow.
2) Don't output so many blank lines. It makes the trace difficult to read. None during a function. One blank when a function exits is OK.

My guess is the sort function is blowing up. Add some trace lines there. Since you never put holder1 nor holder2 back into a[??], you never really sort anything. You just go through the motions and accomplish nothing. You don't even need holder1 and holder2. You can use a[c] and a[c+1] and the sort should function properly. Or nearly so.

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

What does "it doesnt work" mean? Are we supposed to spend our time trying to figure out what it does wrong? Or could you simply explain what it does wrong so we know what to look for?

line 16-19 is the error place...

And that is an accurate description of what the program does wrong, correct? Or is that simply where the problem lies?

Format your code properly and I'm guessing the error will probably smack you in the face. I still don't know what the error is, though.

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

What does "it doesnt work" mean? Are we supposed to spend our time trying to figure out what it does wrong? Or could you simply explain what it does wrong so we know what to look for?

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

I am getting a big problem at the end of my arrange function. It reads the last line of code in the function, but then never leaves the function. I don't care about output at this point. I just want to figure out why I can't leave the function and at least run the entire program. I can fudge stuff around then to tweak the correct output.

Your description is not understandable. When you run a program, it doesn't read the program so it can't get stuck at the end after "It reads the last line of code in the function" Please describe what actually happens to make you think it's not working.

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

And what new information has been added by resurrecting a 3-year old thread? I see nothing that hasn't already been mentioned.

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

And what seems to be the problem and where is it in your code?

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

Ok, It's my turn of trying a different way of solving the problem:
. . .
SO how do you like my code?.

It's bad...
1) Two years too late
2) No formatting making the code hard to follow
3) Using fflush(stdin); -- not defined for input streams
4) Using sequential IFs instead of SWITCH.

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

I disagree.
1) IMO, the # of solved threads is a bogus value to begin with. It has no real purpose and gives a skewed view of most poster's 'help'. It's even less useful than REP.
2) It's not our place to mark threads solved -- it's the OP's place.
3) Just more stuff for the mods to deal with that does not (IMO) add anything to the forum. (Auto-close is a much more useful addition, but let's not go there again :icon_twisted:)

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

First, its not good to open the same file twice. Use just one FILE* pointer and use it for both reading and writing. Call fseek() to move the FILE pointer back to the beginning if you need to but its not necessary to open the file again.

I disagree. IMO it's better to open the file for read, close, then open for write. At least for beginners. But you should close the file before opening it a second time, and use the same FILE*.

The rest of AD's suggestion is right on.

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

If you want help, you need to explain the problem and actually ask a question.

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

I have tried doing a while loop, but it does not seem to work...

Why? Since we can't see your computer, you have to tell us what you see. Are your braces in the wrong place?

Try formatting your code better. You are getting confused because you can't see your blocks correctly.

Shouldn't you display each roll? That's what happens at the casino -- you get to see each throw of the dice, not just the winning/losing roll.

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

What's the difference between an Airplane and a Helicopter?
An airplane is designed to supply thrust and works with the air using the science of aerodynamics to create lift.
A helicopter simply beats the air into submission.

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

Depends on the assembler. There are dozens of possibilities.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
            d1 = rand()%6+1;
            d2 = rand()%6+1;
            sumd = d1 + d2;
            if (sumd==7) {
                printf("You rolled a 7, you lose.\n");
                lostp++;
            }
            if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
                printf("You rolled your points, you win.\n");
                winp++;
            }
        }
    }
}

The logic above is wrong. If you first rolled a 5 (sumd = 5), you get into this section. Then 3 possibilities exist:
1) You now roll a new value (sumd = 7) and loose, which you count.
2) You now roll a new value (sumd = 8) and your next big IF is true. But you did not roll your point. You rolled an 8. 8 != 5.
3) You now roll a new value (sumd = 12) and neither IF is true. So you did not even count this turn.
So if on your first roll you roll a point, you make 1 more roll and you're done.

Look at the instructions again. What are you supposed to do when you roll a point?

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

What does your program print before and after it goes wrong?

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

since fgets will not do what you're trying to do:

It absolutely will.

Because fgets reads the chars in to "an array", and you're giving the address of "three" arrays ((3X3) means array of 3 arrays of chars) to it.

So he gives the address of an array, and tests each character to see if it should be moved to the matrix.

You can easily read chars in to the array with getchar() , no need to use fgets() (unless you've been explicitly told to ).
This example may help you.

You may need to reread his posts and try to understand the format of the file. Your code is woefully inadequate.

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

Since you are "leraning c++ at the moment", I assume it's from a class. If so and you've never heard of vectors, don't bother with them. Your instructor will get there eventually. Your best bet is the array idea.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
int main()
{
     char inarray[3][3];
     int i;

     while(fgets(inarray,sizeof(inarray),stdin) !=NULL)   // read a line from the file
     {
          for(i = 0, i <50; i++)
          { 
             inarray[0][i] = getchar();     // Read a character from the file

So after reading the line from the file, why do you start reading again using getchar() ? You are throwing away the first line. Just read the first line into a temporary buffer (not inarray) and test each character in the array instead of the getchar() .

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

Personal opinion -- If a program blinks at me it's going to be the last time I use it. I would look for a less obnoxious program...

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

There is no pause() function.
I found this.

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

What did SEARCH at the top of the page tell you when you tried to find your answer?

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

Another way is to
1) read your text book
2) check out some tutorials
3) talk to your instructor
4) try something and see if it works.

We are not a homework service, nor a teaching site. Since your task is very basic, you should have learned the basics in your class and be able to at least do something.

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

addition of digits of number if divisible by 3 then that number is divisible by 3.
396=3+9+6=18=1+8=9.
1)store 3,6,9 using enum.
2)sum=0
3)input a string a.
4)convert each char into digit using atoi.
5)add that char to sum and store it in sum.
6)assign sum to a.
repeat this process untill you get a single character.
7)check with 3,6,9 if equals then divisible, else not..

I think this will work out.

No it won't.
A) In order to "4)convert each char into digit using atoi." you need to convert each character into a string first. The overhead for that is huge compared to char - '0' .
B) Then you "6)assign sum to a." But sum is an integer and a is a string. How do you assign an integer to a string?

If you truly think it will work, please post your working code. I'd love to see it...

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

Read a line from the file. Look at each character in the buffer. If it's a letter, add it to the matrix. If it's a \n, move to the next row in the matrix and read the next line.