Author Topic: Need Help in C  (Read 734 times)

ic3y

  • Committee Member
  • Autococker
  • Posts: 1398
Need Help in C
« on: September 29, 2008, 08:39:33 AM »
Code: [Select]
´/* Scanf mit Schleife */
#include <stdio.h>
int main (void)
   
{

int zahl,r;
do {

printf ("Number: ");

r=scanf("%i",&zahl);
fflush (stdin);
printf("R                             : %i\n\n",r);
}while(r==0);

printf("Show Number: %i \n",zahl);


printf("Adress from Number              : %i \n\n", &zahl);


   ;return 0;
}

So I need a
do - while
or anything for restart the program.
I tryed it already but nothing works. Maybe i learn C since 4 hours :P.

So when the programm finished the question come:

Code: [Select]
Want program restart (Y/N)?
By Y the program start again
By N closed the program



I hope you can help me

ic3y

Sry for bad english : D


S8NSSON

  • Autococker
  • Posts: 709
Re: Need Help in C
« Reply #1 on: September 29, 2008, 09:48:19 AM »
Code: [Select]
´/* Scanf mit Schleife */
#include <stdio.h>
int main (void)
  {
int zahl,r;
  do
    {
    do
      {
    printf ("Number: ");

    r=scanf("%i",&zahl);
    fflush (stdin);
    printf("R                             : %i\n\n",r);
      }
    while(r==0);
  printf("Show Number: %i \n",zahl);
  printf("Adress from Number              : %i \n\n", &zahl);
    }
while(stayhere());  // will do the above at least once

    return 0;
}
int stayhere(void)
  {
  int retval = 0;
  // return 1 if staying, 0 if not staying
 
  // This place left for you to write Stay or Leave question 


  return retval;
  }