View Single Post
Old Apr 26th, 2005, 9:34 AM   #2
Eggbert
Professional Programmer
 
Eggbert's Avatar
 
Join Date: Nov 2004
Posts: 250
Rep Power: 5 Eggbert is on a distinguished road
>while (5 == 5) {
This is strange. Not only that you used <constant> == <constant>, but because you chose 5 as the constant. A more conventional way to create an infinite while loop is
while ( 1 ) {
  /* Body */
}
>SUM (int res);
A function call does not declare parameters, it takes arguments:
SUM (n1, n2);
Here is the same program with the necessary fixes:
#include <stdio.h>

int SUM (int n1, int n2);

int main ()
{
  int n1, n2, i;

  while (1) {
    printf ("To close the program, type 0: ");
    scanf ("%d", &i);
    if (i == 0) break;
    printf ("Type the numbers that should be used to do the sum: ");
    scanf ("%d %d", &n1, &n2);
    SUM (n1, n2);
  }
}

int SUM (int n1, int n2)
{
  int res;
  res = n1 + n2;
  printf ("The result is: %d", res);
  return res;
}
Eggbert is offline   Reply With Quote