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

[boilerplate_help_info]

Posing requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]To [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry, I'm not going to fight through all that unformatted code. It's difficult to follow. See this to learn how to format code for readability and easier coding.

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

To begin with:
[boilerplate_help_info]

Posing requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]To [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What I know about footy I learned from the dog in Footrot Flats! And Ol' Wal, of course...

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

If it's beyond your current knowledge, put the task in the shelf for a few weeks and come back to it. You will probably have enough knowledge by then to start tackling the job.

Or search the forums. This has been answered a lot!

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

Read all inputs as strings. Then test to see if all characters are digits and if so, convert to a number and continue. Otherwise, process an error.

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

Yes I have an old fashioned phone, and I have tried the *69 thing but doesn't work, that may be because I live in South Africa, any other solutions?

Hmmm let's see. South Africa. Phone. Ummmmm. Can't think of a thi... No Wait!!!! Call your phone company! Noooo, you'd have to be pretty stupid to not think of that. So obviously the phone company doesn't know. And if the phone company doesn't know it's not likely we would know since few of us live in Africa. Maybe the utilities commission, or the government knows. Sorry to hear about your phone company, though. I'd get another company that knows their system better. You might want to move to Spain.

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

There's too little information for us to make even a guess at what you need. Sorry. Details, code, and design are missing from your question.

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

Your response makes no sense. Input randomly and call the function have nothing in common.

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

Put the menu in a function. Call the function anytime you need it.

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

Hello Again

in the line 28 ERROR (Expected Array)

why???

Probably because on line 28 you used a command that requires an array and you didn't use one.

Since
1) You didn't use CODE Tags
2) You didn't bother to tell us what line 28 is
we can't very well tell what you did wrong. You'll have to post useful information for our understanding.

hkdani commented: Shows understanding in the basic concepts of Visual Basic programming. And based on experience quickly points out valuable insights. +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First of all, it would help for readability to use what are universally accepted variable declarations for variables.

They are far from universal.

Experienced programers used to accepted standards could easily mistake your variables for the wrong type.

No we don't... Standards of this type are company or personal standards, not universal. There are many other standards that don't use str, lng, etc. Any of them are acceptable, some are better than others.

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

Try it without the bastardized *_s functions. Just use fscanf() and fopen() . They are standard and work in all compilers.
Be sure to check the syntax of fopen() because it's different than your use of fopen_s()

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

You can't assign an array to an array like that. Use a loop.

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

To copy to another location, open the file in binary mode then read/write 255 bytes at a time until end-of-file is reached. Another way to do it on MS-Windows is call win32 api function CopyFile()

I'd use 256. It fits better in the realm of binary. Any power of 2 would work.

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

Is counter a single variable or an array?

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

Depends on what you mean by interact. Nothing kinky I hope.

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

RTFM.

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

Reread your text on printf() format specifiers. Specifically the %f specifier.

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

You forgot to add graphics.lib to the compile.

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

ayeshashahid, can't be done, next input will put in the nextline.

Since there is only one cin , there is no next input.

You should just ask for each grade individually. Print the test such as "Prelim" and then wait for input and <enter>. This could be the resulting program output:

And how does that help him align the output to the header he displayed :icon_rolleyes:

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

You cannot define a function ( RadiusofTwoSpheres ) in the middle of another function ( main() )

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

Ok the thing I searched into google brought up a ton of nonsense.

Lack of understnding does not make the information nonsense...

I want to use variables from a function in main...

Pass the values back to main() when the function returns.

... and (more important) variables from main in a function.

Pass the values into the function in the parameter list.

Both of these can easily be found in any tutorial or book on C/C++.

PS How do I combine strings?

Depends on the type of 'string' you use. Either a simple + if you're using strings or strcat() if using char*

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

Then you did it wrong. But you didn't bother to show us what you did, so we can't be more specific.

And u is not an English word. Please don't use leet speek on the forums.

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

Hi ,

can you plz explain it with code :)

thanks for your help

No. We to not write homework programs for people. That's your job as the student. We can help you when you get stuck, but based on your posts, you aren't stuck since there's no attempt to solve the problem.

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

When will noobies stop posting questions without the information they have that can easily answer their question?

When posting errors, don't post a part of the error -- copy and paste the ENTIRE error, verbatim, including line number, listed code, EVERYTHING.

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

Yeah, can you finish his homework for him? He has to pass the class, you know.

Süspeñce commented: no need to tell me ..i know better -1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As L7sqr implied:

int myatoi( char *x ) {

    int y = ( *x - 48 );  // convert the first character into an integer
                          // What about the second, third,... characters?
    return y;
}

Think loop...

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

Wait I can really do that!?!

No. I only said that because you won't accept that a portable CLS cannot be done.
Honest, it cannot be done.

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

Oh, why can't I just extract the code widows runs when cls is called and put that in my program?

Go for it...

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

Same way

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

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

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

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

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

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

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
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

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
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

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.

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

Read a character at a time. If it's a letter, add it to the matrix. If it's a \n, move to the next row in the matrix.

Read the words into an array.

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

You have to create the "file1.dat" filename each time through your loop. You need stringstream or sprintf or something similar to do that.

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

the parameters taking of printf function is from right to left.....
So in the given problem the function executes as follows....

b=1;
printf("\n %d %d %d",b=15, b>9, b<9);

So first it executes the condition b<9 but here b=1
next it executes the condition b>9. Here also b=1
and the last step is b=15 will executes.........

Please reread Narue's post. She is correct, you are mistaken.

i get this but why it happens only in case of printf???

What makes you think it only happens with printf?

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

It's the web link to the post itself. You could have just clicked it...

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

I'm having trouble getting this program to work for roman numeral conversion. I hope it says that i have one error, which is C2110: cannot add two pointers. here's what i have so far... ANY help would be great

1) Use CODE Tags
2) Don't tell us you hope for an error, tell us exactly what error you get
3) Don't make us guess what line the error is on. Tell us. We aren't psychicprogrammers.com you know.

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

Look, you can't program by
1) running the code,
2) seeing that it doesn't work
3) arbitrarily changing something
4) going back to 1

You need to
A) Think about what you are doing
B) Test what you try
C) If it doesn't work, find out why
D) Fix it

I want you to do three things:
1) Place comments on each line of your code that explains why that line is there. "Because someone said so" is not acceptable.
2) Write down the steps needed in detail to check the beginning of the file for your bad file indicators
3) Start outputting values to see if each variable, each array element, etc contains what you think it should -- based on #2

And if your present code doesn't look like it will be easy to fix, start over and do only the beginning-file test. Once that works, add the end-file test.