#include<stdio.h>
#include<string.h>
#define size 21
#define max 5
int id[max][size];
char ln[max];
int pr[max];
int mt[max];
int fg[max];


void getrecord()
{
int i;
for(i=0;i<=4;i++)
{
clrscr();
printf("id number:");
scanf("%d",id[i]);
printf("last name:");
scanf("%s",ln[i]);
printf("prelim:");
scanf("%d",pr[i]);
printf("midterm:");
scanf("%d",mt[i]);
fg[i]=(pr[i]*0.4)+(mt[i]*0.6);
}
getch();
}

void displayreverse()
{
int i,p;
clrscr();
printf(" idno.  lstnme  prelim  midterm  fgrde");
for(i=4;i<=0;i--);
{
p=0;p++;
gotoxy(5,9+p);
printf("%d",id[i]);
gotoxy(5,9+p);
printf("%s",ln[i]);
gotoxy(5,9+p);
printf("%d",pr[i]);
gotoxy(5,9+p);
printf("%d",mt[i]);
gotoxy(5,9+p);
printf("%d",fg[i]);
}
getch();
}

main()
{
getrecord();
displayreverse();
exit(0);
}

Recommended Answers

All 19 Replies

can someone help me??
this is a program i created wherein the function getrecord() accepts data up to 5 times and a displayreverse() wherein it display all the data from the last input to the first input.

it works but it doesn't display the output!

Is there something wrong in my displayreverse() function??
pls help me!!!! HELP!!!

Please describe your problem a bit more. What are the errors that you are getting?

Which compiler are you using???

i can't display the outputs.
like when i entered all the data 5times in the getrecord()
when it goes to the function displayreverse after inputing all the needed data, it does not display all the output. the output is just

" idno. lstnme prelim midterm fgrde"

and the inputted data didn't appear at all even though i entered all the data needed

Here are some problem with your code

1)

printf("last name:");
scanf("%s",ln[i]);

replace it like

printf("last name:");
scanf("%s",ln);

2) The same problem with other scanf also. Give address to scanf.
ex :

scanf("%d",&(pr[i]));

i'm using a borland turbo C

my problem is not in inputting the data, but in displaying the outputs.
like for example:

when i input all the data: like
id number:1
lastname:smith
prelim:60
midterm:100

id number:23
lastname:wirth
prelim:65
midterm:100

id number:3
lastname:smith
prelim:60
midterm:76

id number:3
lastname:taylor
prelim:55
midterm:15

id number7
lastname:scott
prelim:6
midterm:10

so i get a 5 inputs,and then after inputting it should display all these data in the screen.

can someone help me??

Try changing this part in displayreverse()

void displayreverse()
{
    int i,p;
    printf(" idno.  lstnme  prelim  midterm  fgrde");
    for(i=4;i>=0;i--);
    {

Please do not use clrscr , and gotoxy . Those functions are not standard functions. Since you are obviously a student, try to learn the correct usage of the C language. Modern compilers which are more standard compilant than TurboC does not compile your program. Search for the DevCPP compiler in google and download it. It is a very good compiler for beginners.

i'm using a borland turbo C

That's your first big mistake! toss that crappy compiler into the bit bucket (delete it from your computer) and get a modern C compiler that you can use to learn the C and C++ languages correctly. You can't learn to drive a 2007 automobile by riding a horse & buggy, so why attempt to learn current computer languages with a compiler that was created probably before you was born?:eek: You can get a very good Dev-C++ compiler for free.

>int id[max];
That is a 2-dimensional array of integers, what you want is a simple one-dimensional arry, like this:
int id[max];

After using scanf() to input an integer the keyboard buffer will still contain the <Enter> key, or '\n'. You need to remove that from the keyboard buffer before calling scanf() again or scanf() will not stop for keyboard input. You can remove the '\n' key by calling getchar().


Dilip already provides some advice -- read it, implement it, then repost your program if you still have problems.

#include<stdio.h>
#include<string.h>
#define size 21
#define max 5
int id[max];
char ln[max][size];
int pr[max];
int mt[max];
float fg[max];

void getrecord()
{
int i;
for(i=0;i<=4;i++)
    {
    clrscr();
    printf("\nid number:");
    scanf("%d",&id[i]);
    printf("\nlast name:");
    scanf("%s",ln[i]);
    printf("\nprelim:");
    scanf("%d",&pr[i]);
    printf("\nmidterm:");
    scanf("%d",&mt[i]);
    fg[i]=(pr[i]*.4)+(mt[i]*.6);
    getch();
    }
getch();
}

void displayreverse()
{
int i,p;
clrscr();
printf(" idno.  lstnme  prelim  midterm  fgrde");

        gotoxy(5,3);
        printf("%d",id[4]);
        gotoxy(10,3);
        printf("%s",ln[4]);
        gotoxy(12,3);
        printf("%d",pr[4]);
        gotoxy(18,3);
        printf("%d",mt[4]);
        gotoxy(20,3);
        printf("%.2f",fg[4]);
                gotoxy(5,4);
        printf("%d",id[3]);
        gotoxy(10,4);
        printf("%s",ln[3]);
        gotoxy(12,4);
        printf("%d",pr[3]);
        gotoxy(18,4);
        printf("%d",mt[3]);
        gotoxy(20,4);
        printf("%.2f",fg[3]);
        gotoxy(5,7);
        printf("%d",id[2]);
        gotoxy(10,7);
        printf("%s",ln[2]);
        gotoxy(12,7);
        printf("%d",pr[2]);
        gotoxy(18,7);
        printf("%d",mt[2]);
        gotoxy(20,7);
        printf("%.2f",fg[2]);
        gotoxy(5,9);
        printf("%d",id[1]);
        gotoxy(10,9);
        printf("%s",ln[1]);
        gotoxy(12,9);
        printf("%d",pr[1]);
        gotoxy(18,9);
        printf("%d",mt[1]);
        gotoxy(20,9);
        printf("%.2f",fg[1]);
        gotoxy(5,10);
        printf("%d",id[0]);
        gotoxy(10,10);
        printf("%s",ln[0]);
        gotoxy(12,10);
        printf("%d",pr[0]);
        gotoxy(18,10);
        printf("%d",mt[0]);
        gotoxy(20,10);
        printf("%.2f",fg[0]);





    
getch();
}

main()
{
 clrscr();
 getrecord();
 displayreverse();
 exit(0);
}

Why did you post that? Are you having any other problems?

here is the new code of my running program. i solve it already. thanks to the help of others!! But my code is not that practical to use because i didn't use a loop instead i typed all the needed data one by one in the displayreverse function inorder to display all the data inputted by the user from the last input up to the first input.

But still i'm hoping to run this program using a loop.Because when i'm using a loop to display the data it won't display anything.

By the way, I'm also planning to learn Dev-C++ for me to be able to understand more deeply "C".
Thanks for the advice.:cheesy:

But still I can't escape in using borland turbo C because this is what we use in our school (subject: CS 211 in our school ).:sad:
"what a crappy school!! right??!!!!":-|:sad:

here is the new code of my running program. i solve it already. thanks to the help of others!! But my code is not that practical to use because i didn't use a loop instead i typed all the needed data one by one in the displayreverse function inorder to display all the data inputted by the user from the last input up to the first input.

But still i'm hoping to run this program using a loop.

By the way, I'm also planning to learn Dev-C++ for me to be able to understand more deeply "C".
Thanks for the advice.:cheesy:

You are welcome.

But still I can't escape in using borland turbo C because this is what we use in our school (subject: CS 211 in our school ).:sad:
"what a crappy school!! right??!!!!":-|:sad:

Yeah school is crappy. But use DevCPP at home. Maybe code that works in DevCPP will work in TurboC, although not the otherway around (not sure about that but stick with code that works in DevCPP as much as possible ). Thank god I didnt learn programming at school :cheesy:

Some general advice

1) Donot use clrscr(), getch, gotoxy and all.....
2) Use prototype of main as int main(void) ( The one comment I usually get from the forum) or int main(int argc, char*argv[])
3) Dont avoid any warnings from your compiler. Try to fix that also.
I think you might have got some warning for the exit() function used in the your code. If you are using exit(), include stdlib.h.
4) Try to use minimum number of global variables in your programm. ( They can be modified from any where)

Thats all for now ..........

#include<stdio.h>
#include<string.h>
#define size 21
#define max 5
int id[max];
char ln[max][size];
int pr[max];
int mt[max];
float fg[max];

void getrecord()
{
int i;
for(i=0;i<=4;i++)
    {
    clrscr();
    printf("\nid number:");
    scanf("%d",&id[i]);
    printf("\nlast name:");
    scanf("%s",ln[i]);
    printf("\nprelim:");
    scanf("%d",&pr[i]);
    printf("\nmidterm:");
    scanf("%d",&mt[i]);
    fg[i]=(pr[i]*.4)+(mt[i]*.6);
    getch();
    }
getch();
}

void displayreverse()
{
int i,p;
clrscr();
printf(" idno.  lstnme  prelim  midterm  fgrde");
for(i=4;i>=0;i--)
    {
        
        printf("\n%d   %s   %d   %d   %.2f",id[i],ln[i],pr[i],mt[i],fg[i]);

    }
getch();
}

main()
{
 clrscr();
 getrecord();
 displayreverse();
 exit(0);
}

:cheesy:Finally!!,I run my program using a looping!!
thanks for the advice dillip!!!
because of your advice i finally run my program using a loop!! THANKS A LOT!!:cheesy::cheesy::D:cheesy::cheesy::lol::lol::lol:
thanks also for others

But use DevCPP at home. Maybe code that works in DevCPP will work in TurboC, although not the otherway around (not sure about that but stick with code that works in DevCPP as much as possible).

As long as standard C is used, Turbo and Dev are compatable. There is nothing wrong with Turbo C (even down to Turbo V1). It implements the same stuff the "current compilers" have implemented. It just has a few more "enhancement functions" that are not in the new packages (interrupts, graphics, screen capabilities) and it compiles in 16 bits. Although I agree a school should be using an up-to-date compiler.

Saying Turbo is crap is like saying the Dick Van Dyke Show is crap because it's a 1960's show. It's still better than most comedies on TV today... :)

Saying Turbo is crap is like saying the Dick Van Dyke Show is crap because it's a 1960's show. It's still better than most comedies on TV today... :)

Well, let us know what schools teach 1960s programming styles? and use 1960s computers (how may of you have used punch cards to do all your programming?)

Turbo C was a great compiler in its day (1980s) (best on the market), but has outlived its usefullness. 16-bit MS-DOS is nearly dead and almost buried, I say almost because there are a very few 16-bit commercial programs still around.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.