Back to top in C

Asked

Viewed 414 times

1

I created a calculator in C, with menu and everything, with the switch case when choosing a function from +, -, *, /, etc. You enter two values and they are executed according to the function. How to do after the arithmetic operation, the program goes back to the main menu to be able to choose another operation?

2 answers

4

Put a while before or between the main code, where it waits for a char(s/n), on the first run already initialize a variable(opcao) with s, after the operation do the writing of something like deseja efetuar mais calculos S/N? then do the reading with scanf(), after this evaluation will be made of opcao no while, if s makes another account otherwise closes the program.

0

You can also use goto and labels:, since you’re using C. Example:

inicio:
print("teste");
goto inicio;
  • 2

    Use the goto should be avoided, only used when the code cannot be written in a more readable manner.

  • I just wanted to demonstrate another way of how it can be done. The use or not use of Labels and Gotos does not enter much into the merit of his question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.