Okai, so this is the program I have reached, it works perfectly. But there is one thing I need. I need to add a Y/N function. What I mean is I want for there to be a question to ask the user at the end of the program, 'Do you want to make an other calculation and for it to go from the beginning if I write Y and exit if I write N.
#include <stdio.h>

And basically we are using the C-free compiler, and this is extreme basics of the c programming. All we have took is shown to you here, with the addition of for loops and while loops.

01-07-2013

grumpy

None of that code is relevant to a "Y/N" function (except, presumably, you want to use that "Y/N" function somewhere in all that).

Have you tried writing a function that behaves like your "Y/N" function might? (for example, writing a prompt, and then returning an indication of whether Y, N, or something else was entered by the user)

Try doing that first. One you have done that, see if you can work out where to call it, and how to make your code loop.

01-07-2013

Moody Barrawi

Oooh, so i make a function that behaves like a loop that only goes out if N was put, and go around in the loop if I press Y. And I should make all of the MAIN program inside this function is what you are saying?

01-07-2013

grumpy

No. I'm saying don't worry about the loop just yet.

I'm saying writing a function that prompts the user, receives user input, and then returns an indication of what was input.

Once you have a function like that, you can work where to add a loop construct. One part of the loop will be a call to said function. Another part of the loop will be code you want to do over and over again.

01-07-2013

Moody Barrawi

So does the function go like char x; printf "do you want to do an other conversion"; then scanf "%c",'x' then if x==N | x==n then exit the program and if x==Y | x==y then repeat the program?

01-07-2013

c99tutorial

I think the suggestion is to start simple. For example, you could start with the "Hello world" program and add a yes/no function to that.

1. Print "Hello World"
2. Ask the user "Do you want to see it again? (y/n)"
3. Read the answer
4. If the answer is "y", repeat step 1.

That is the procedure outline. You will want to use either a "for" or a "while" or a "do...while" construction to implement the loop from 4. to 1.

01-07-2013

Moody Barrawi

I know how to do that but my program is in a big scale. So I kind of get confused :p

01-07-2013

c99tutorial

That's the reason for starting small. Do the loop with a small program, and when it works... do the same on the large program.