Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 27th, 2005, 12:16 AM   #1
Planet_EN
Programmer
 
Join Date: Mar 2005
Posts: 40
Rep Power: 0 Planet_EN is an unknown quantity at this point
Table in C language???

I have to make a table in which a user can input values horizontally in a table row...
user should enter the number of students and then a table must be generated of that size
like this ...

Name ..........<space>........ Marks in Subject-1 ..........<space>........ Marks in Subject-2...

But the confusion lies because I have to do it in C language without arrays and functions, only by the use of for loop, if condition and gotoxy statement.

I'v tried gotoxy statement but it isnt working properly ... please help me for this program ...

Last edited by Planet_EN; Mar 27th, 2005 at 12:29 AM.
Planet_EN is offline   Reply With Quote
Old Mar 27th, 2005, 10:51 AM   #2
Planet_EN
Programmer
 
Join Date: Mar 2005
Posts: 40
Rep Power: 0 Planet_EN is an unknown quantity at this point
bump ...
Planet_EN is offline   Reply With Quote
Old Mar 27th, 2005, 11:06 AM   #3
Planet_EN
Programmer
 
Join Date: Mar 2005
Posts: 40
Rep Power: 0 Planet_EN is an unknown quantity at this point
The first problem is that i cant align the fields in the appropriate manner ...
Planet_EN is offline   Reply With Quote
Old Mar 27th, 2005, 11:09 AM   #4
Planet_EN
Programmer
 
Join Date: Mar 2005
Posts: 40
Rep Power: 0 Planet_EN is an unknown quantity at this point
here the program

#include<stdio.h>
#include<conio.h>

void main()
{
  int x,inputs,loop1,sum;
  clrscr();
  for(x=1;x<=80;x++)
  {

      gotoxy(x,1);
      printf("\xCD");

  }

  printf("Name\tSubject-1\tSubject-2\tSubject-3\tSubject-4\tSubject-5\tTotal\tPer\tAverage");
  for(x=1;x<=80;x++)
  {

      gotoxy(x,3);
      printf("\xCD");

  }
  for(loop1=8;loop1<=88;loop1+=10)
    {
    gotoxy(loop1,4);
    scanf("%d",&inputs);
    printf("\t");
    sum=sum+inputs;
    inputs=0;
    }
 }
Planet_EN is offline   Reply With Quote
Old Mar 29th, 2005, 10:16 AM   #5
Planet_EN
Programmer
 
Join Date: Mar 2005
Posts: 40
Rep Power: 0 Planet_EN is an unknown quantity at this point
Question Alignment problem ...

Here's my final program ... But its still having some alignment problem ... can anyone help ????

#include<stdio.h>
#include<conio.h>

void main()
{
  int x,inputs,ColumnHandler,sum,rows=1,nos;
  char name[25],grade;
  float per;
  x=inputs=sum=ColumnHandler=per=0;
  clrscr();
  printf("Enter the number of students : ");
  scanf("%d",&nos);
  clrscr();
    for(x=1;x<=80;x++)
  {

      gotoxy(x,1);
      printf("\xCD");

  }

  printf("Name %c%c%c%c",32,32,32,32);
  printf("Elect%c%c%c%c",32,32,32,32);
  printf("Cal-1%c%c%c%c",32,32,32,32);
  printf("CP-1 %c%c%c%c",32,32,32,32);
  printf("DMath%c%c%c%c",32,32,32,32);
  printf("  Acc. %c%c%c%c",32,32,32,32);
  printf(" Total%c%c%c%c",32,32,32,32);
  printf("Per  %c%c%c%c",32,32,32,32);
  printf("Grade");
  for(x=1;x<=80;x++)
  {

      gotoxy(x,3);
      printf("\xCD");

  }

  for(;rows<=nos;rows++)
  {

    gotoxy(1,4+rows);
    scanf("%s",name);

  for(ColumnHandler=10;ColumnHandler<=60;ColumnHandler+=10)
    {

      if(ColumnHandler<=50)
       {
	gotoxy(ColumnHandler,4+rows);
	scanf("%d",&inputs);
	sum=sum+inputs;
	inputs=0;
       }
      else
       {
	gotoxy(ColumnHandler,4+rows);
	per=sum/5;
	printf("%d%c%c%c%c%c%.0f%c%c%c%c%c",sum,32,32,32,32,32,per,32,32,32,32,32);
	if(per>90)
	  printf(" A+");
	else if(per<=90&&per>80)
	  printf(" A");
	else if(per<=80&&per>70)
	  printf(" B");
	else if(per<=70&&per>60)
	  printf(" C");
	else if(per<=60&&per>50)
	  printf(" D");

	sum=per=0;
	}
     }
   }
  getch();
}
Planet_EN is offline   Reply With Quote
Old Mar 31st, 2005, 10:09 AM   #6
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 314
Rep Power: 4 mackenga is on a distinguished road
No offence, but that's some pretty twisted code. In your printf() format strings, you have multiple %c (character) parts, followed by the constant 32. This is exactly the same as just including a space in the format string. I can't see any reason for doing it this way.

The problems with the layout will be because you output the same number of spaces to pad out columns no matter what the length of the actual content is. I haven't actually tried the program (I can only get online at the library at the moment and their machine doesn't even have a C compiler...I feel claustrophobic!) or looked at it in great detail (running it would help with that) but I notice that nowhere in your program does it seem to measure strings and calculate the amount of padding required.

Not sure about this, but you always, in your program, count co-ords on the screen from 1 up to for example 80, not 0 to 79, which looks a little strange to me. Are you sure you shouldn't be counting from zero? Like I say I'm not sure if this is right. You might well know better than I do in this regard.

Ah, I see you don't actually need to calculate padding because you're always using gotoxy() to go to where the fields ought to start; so probably disregard at least some of what I've said here. The only other thing that springs to mind that could be giving you layout issues is the fact that each time input is read, it's echoed, which will move the cursor. Are you accounting for that?

Just one last thing; your choice of variable names is a bit bizarre. This makes it much harder to skim your program and see what's going on. It took me about five minutes of frowning to realise that ColumnHandler is just an int, and with that long name and those CapitalLetters in it, I couldn't help thinking of it as a class

Hope I've said something helpful in this rambling post.
mackenga is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC