# Thread: Help with strings and numbers ;[

1. ## Help with strings and numbers ;[

Hi, first, I'm from Brasil, so sorry for any eventual english errors ;p
K =D Here's the deal, I need to build a programa that read 20 names, and 3 notes (ratings ? scores ?) (like 6,0 , 4,5 , 7,0 ...) and made a average rating..., and if I write END in a name, the programa stops collecting names and notes...

Until now I did this:

Code:
```for (CONTN=0;CONTN<3;CONTN++)
{
printf ("\nEnter a name:");
gets (NAME[CONTN]);
for (CONTY=0;CONTY<3;CONTY++)
{
printf ("\nNote %d:",CONTY);
scanf ("%f",&NOTE[CONTN][CONTY]);
SOMA = SOMA+NOTE[CONTN][CONTY];
}
AVG = SOMA/3;
NOTE[CONTN][3] = AVG ;
}
printf ("Name, Avg");
for (CONTN=0;CONTN<2;CONTN++)
{
printf ("\n%s %f",NAME[CONTN],AVG);
}
}```
Its suposed to get the name, and 3 notes, so made a average note , and after all, print this on the screen...

Buuuttt... it's all wrong =/ I really dont know what is wrong... And dont know how to do that if-write-END-stops... if someone can help-me, I will be very pleased...

Thanks =]

2. Code:
`for (CONTN=0;CONTN<3;CONTN++)`
This runs 3 times so for 20 names change 3 to 20.
When a name is entered compare it with "END" and if they are equal use break to exit the for loop.
Code:
```if (!strcmp(NAME[CONTN], "END"))
break;```
Code:
`SOMA = SOMA+NOTE[CONTN][CONTY];`
make sure that SOMA is set to zero before entering the 3 scores as it will have the total from the last names.

You should also count the number of names that were entered before END and use this count in the final for loop that displays averages.

3. Hum... thanks for the code to compare the END.

Did what you said... When I start the program it already jumps for the Note 0 part.. Like:

Code:
```Enter a name:
Note 0: [so if I write, the name appears here]

Note 1:
Note 2:
Enter a name: [and write another name...]
Note 0:```
... Basicly its not geting the Notes (I cant insert them =p) ... And just ignoring the FOR I did for the notes (where it should be NOTE[0][0], NOTE [0][1], etc =[

Thanks again =]

4. So the program just exists after you entered the first name? Post the complete program.

5. Here it is:

Code:
```#include <stdio.h>
#include <conio.h>
#include <string.h>

int main ()
{
float NOTA[3][4],MEDIA,SOMA;
int CONTN,CONTY,CONTA;
char NOME[3][31];
SOMA = 0;
CONTN = 0;
CONTY = 0;
CONTA = 0;
for (CONTN=0;CONTN<3;CONTN++)
{
printf ("\nDigite o nome:");
gets (NOME[CONTN]);
CONTA = CONTA++;
if (!strcmp(NOME[CONTN], "fim"))
break;
for (CONTY=0;CONTY<3;CONTY++)
{
printf ("\nNota %d:",CONTY);
scanf ("%f",&NOTA[CONTN][CONTY]);
SOMA = SOMA+NOTA[CONTN][CONTY];
}
MEDIA = SOMA/3;
NOTA[CONTN][3] = MEDIA;
}
printf ("Nome, Media");
for (CONTN=0;CONTN<CONTA;CONTN++)
{
printf ("\n%s %.2f",NOME[CONTN],MEDIA);
}
getch();
}```
The first name apparently goes ok... after that it goes wrong =o

BTW: I'm just testing with 3 names first...
BTW²: I'm using portugues words.. (Nome = Name) (Media = Average)

Thanks... again ;[

6. Why is this in the C++ forum ?

7. yes it belongs in c.

change the part the get the name to this
Code:
```printf ("\nNota %d:",CONTY);
char Line[31];
gets(Line);
sscanf(Line, "%f", &NOTA[CONTN][CONTY]);```
scanf must be leaving the newline charactor which the next call to gets reads in instead of the next line.