MK27
Thanks for CTRL-F5, My teacher is z*** brain I think, I noticed a bit from the start.
memcpy
Still awful indentation, I see.
Don't use fflush(stdin) -> FAQ > Why fflush(stdin) is wrong - Cprogramming.com
I will read this.
Don't use void main, it's outdated and bad practice.
So what do I use? I don’t know?
There's a much better way for takenum() that doesn't use another random "error" function, can you find it?
You want I put the if from the random error function to the takenum() ?
>> Put the include files before the function prototypes; it is a more common ordering.
This is actually really important, not only is it non-standard, sometimes your #includes will define structures that are used in the function prototypes, and because C reads from the top down, it will report them as errors.
Ok, I done it I got 18 error.
Code:
void banner()
{
printf(" **************************************************************\n");
printf(" * *\n");
printf(" * This program add two number *\n");
printf(" * *\n");
printf(" **************************************************************\n");
}
int takenum()
{
int in1,error;
do{
printf("Enter number %d:",p);
scanf("%d",&in1);
error=in1;
error_message(error);
}while(error==0);
p=p+1;
return(in1);
}
void numf(int num1, int num2)
{
int sum;
sum=num1+num2;
printf("The sum of this two number is %d",sum);
getch();
}
void error_message(int error)
{
if(error==0)
{
printf("\n*** Illegal character***\n");
printf("\nPress any key to continue\n");
getch();
fflush (stdin);
}
}
void numf(int, int);
int takenum ();
void banner(void);
void error_message(int);
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
int p=1;
void main()
{
int number1, number2;
int a[20],k,sum;
int i;
sum=0;
banner();
number1=takenum();
number2=takenum();
i=0;
a[i]=number1;
do{
i++;
a[i]=number1+i;
}while(a[i]<number2);
printf("The numbers are\n");
i=0;
do{
printf("%d\t",a[i]);
sum=sum+a[i];
i++;
}while (a[i]<number2);
sum=sum+number2;
printf("\n\nThe sum is %d",sum);
getch();
}
stahta01
FYI: Your teacher is a idiot and is not teaching you to program correctly!!
What can I do, Im in a S*** uni.
I got good grades in college but just a small mistake brought me here.
I wanted to become a pharmacist or medicine lol
Latest programme working:
Code:
void numf(int, int);
int takenum ();
void banner(void);
void error_message(int);
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
int p=1;
void main()
{
int number1, number2;
int a[20],k,sum;
int i;
sum=0;
banner();
number1=takenum();
number2=takenum();
i=0;
a[i]=number1;
do{
i++;
a[i]=number1+i;
}while(a[i]<number2);
printf("The numbers are\n");
i=0;
do{
printf("%d\t",a[i]);
sum=sum+a[i];
i++;
}while (a[i]<number2);
sum=sum+number2;
printf("\n\nThe sum is %d\n",sum);
}
void banner()
{
printf(" **************************************************************\n");
printf(" * *\n");
printf(" * This program add two number *\n");
printf(" * *\n");
printf(" **************************************************************\n");
}
int takenum()
{
int in1,error;
do{
printf("Enter number %d:",p);
scanf("%d",&in1);
error=in1;
error_message(error);
}while(error==0);
p=p+1;
return(in1);
}
void numf(int num1, int num2)
{
int sum;
sum=num1+num2;
printf("The sum of this two number is %d",sum);
}
void error_message(int error)
{
if(error==0)
{
printf("\n*** Illegal character***\n");
printf("\nPress any key to continue\n");
getch();
fflush (stdin);
}
}