-
March 6th, 2011, 07:51 PM
#1
C problem with struct
Hi everybody,
I have create the following program:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int menu(void);
void enter_invoice();
void display_invoice();
void total_amount();
int elegxos (int s[9]);
struct apodeixi {
int afm[9];
float poso;
} katalogos[10];
int elegxos (int s[9])
{
int athrafm,ypolafm;
athrafm=(256*s[0])+(128*s[1])+(64*s[2])+(32*s[3])+(16*s[4])+(8*s[5])+(4*s[6])+(2*s[7]);
ypolafm=athrafm%11;
if ((ypolafm%10)==s[8])
{
return 1;
}
else
return 0;
}
int main(void)
{
int choice;
do {
choice = menu();
switch(choice) {
case 1: enter_invoice(); /* Eisagogi apodeikseon */
break;
case 2: display_invoice(); /* Emfanisi apodeikseon */
break;
case 3: total_amount(); /* Emfanisi Sinolikou Posou */
break;
}
} while(choice!=4);
return(0);
}
menu(void)
{
int choice;
printf ("Make a choice from the menu:\n");
printf (" 1. Enter Invoice\n");
printf (" 2. Display Invoices\n");
printf (" 3. Total Amount of the Invoices\n");
printf (" 4. Quit\n\n");
do {
printf ("Make a choice: ");
scanf ("%d", &choice);
} while (choice<1 || choice>4);
return choice;
}
void enter_invoice(void)
{
int i, j, s[9];
/* float poso;
j = 0;
m = 0;
d = 0;
/*
if(m==10)
{
printf("Katalogos Gematos");
break;
}
printf("Please enter AFM\n");
for(j=0; j<9; j++)
do {
printf(" %do arithmos apo to AFM: ",j+1);
scanf ("%i",&s[j]);
} while (s[j]<0 || s[j]>9);
if (elegxos(s)==1)
{
printf(" The AFM is Valid \n");
printf("Please enter the amount: ");
scanf("%f", &poso);
if (poso>0)
{
for(i=d;i<10;i++)
{
for(j=0;j<9;j++)
{
katalogos[i].afm[j] = s[j];
katalogos[i].poso=poso;
}
}
d+=1;
m+=1;
}
}
else if (elegxos(s)==0) printf(" The AFM is not Valid\n");
/*break;
*/
for(i=1; i<=10; i++)
{
printf("Please enter AFM\n");
for(j=0; j<9; j++)
do {
printf(" %d digit from AFM: ",j+1);
scanf ("%d",&s[j]);
} while ((s[j]<0 || s[j]>9));
if (elegxos(s)==1)
{
printf(" The AFM is Valid \n");
for(j=0;j<9;j++)
katalogos[i].afm[j] = s[j];
}
else if(elegxos(s)==0)
{
printf(" \nThe AFM is not Valid. Please re-Enter the AFM\n");
continue;}
printf("Please enter the amount: ");
scanf("%f", &katalogos[i].poso);
break;
}
}
void display_invoice(void)
{
int i, j;
for (i=1; i<=10; i++)
{
printf("The %d AFM: ",i);
for (j=0; j<9; j++)
{
printf("%d", katalogos[i].afm[j]);
}
printf(" The Amount is: %f\n", katalogos[i].poso);
}
}
void total_amount(void)
{
int i;
float sum;
sum=0;
for (i=1; i<10; i++)
{
sum +=katalogos[i].poso;
}
printf("The total amount of the invoices is: %f\n", sum);
}
A valid AFM is 122635660
And I have several problems:
a) When everytime I press 1 and start entry numbers the already registered numbers delete and the data entry begins from the start
b) When I make a wrong entry the program take me to the next line of the table
c) and last but not least, when I press a char in the menu the whole program stucks.
Thanx in advance
-
March 7th, 2011, 07:16 AM
#2
Re: C problem with struct
Originally Posted by vdioniso
I have create the following program:
Please use code tags. [code]your code here[/code]
Originally Posted by vdioniso
And I have several problems:
a) When everytime I press 1 and start entry numbers the already registered numbers delete and the data entry begins from the start
b) When I make a wrong entry the program take me to the next line of the table
Did you step through your program with the debugger? Which compiler/environment are you using?
Originally Posted by vdioniso
c) and last but not least, when I press a char in the menu the whole program stucks.
I didn't look at your code (because it's too hard to read without code tags), but from your question it seems like this might be helpful: http://www.parashift.com/c++-faq-lit....html#faq-15.2
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|