# Matching numbers

• 07-21-2008
kirksson
Matching numbers
I have to print out the matching numbers from a text file. I have to rewrite my int lottery function to do the matching part but not sure how.

here is the output:

Sample input file (lottery.txt)
19 12 26 34 5 17
7 5 12 43 5 26
15 19 3 30 27 41
12 12 12 12 12 12
34 12 5 19 17 26

Sample Output
Ticket #1 has 3 matching numbers
Ticket #2 has 0 matching numbers
Ticket #3 has 1 matching numbers
Ticket #4 has 6 matching numbers

Thanks for any input.
• 07-21-2008
tabstop
I think the matching part was the only part you had right.

scanf("%d \n", readticket) makes no sense whatsoever.

if (lottery==0) means you only print a message if they don't match at all.

You use & when you do scanf, not when you do printf.
• 07-21-2008
MacGyver
Just to give everyone the satisfaction of how bad this code is:

Code:

#include <stdio.h>

int lottery(int ticket[], int winning[]);

int main(void)
{
FILE *fin;
int winning[6],ticket[6];
int i,j;
fin = fopen("lottery.txt", "r");

for(i=0; i<6;i++)
{
printf("&#37;d ", winning[i]);
}

while(!feof(fin))
{
if(lottery==0)              //compare ticket, winning using lottery func
printf("Ticket# %d has %d matching numbers \n",&ticket,&winning);              //print
}
system("PAUSE");
return 0;
}

{
int i;
for(i=0;i<6;i++)
fscanf(fin,"%d", &ticket[i]);

}

int lottery(int ticket[], int winning[])
{
{
int i;
int k;
int count=0;

for (i=0;i<6;i++)
for(k=0;k<6;k++)

if (ticket[i]==winning[k])

count++;

return count;
}
}

Code:

LotteryTicket.c: In function `main':
LotteryTicket.c:23: warning: int format, different type arg (arg 2)
LotteryTicket.c:23: error: syntax error before '/' token
LotteryTicket.c:27: warning: implicit declaration of function `system'
LotteryTicket.c:11: warning: unused variable `ticket'
LotteryTicket.c:12: warning: unused variable `j'

As tabstop and my compiler both pointed out, your scanf() is wrong. Always fix syntax errors first so you can test the logic itself instead of wasting time with stupid things like this. This will most likely just waste time crashing your program. If your compiler is not spitting out these types of errors, you need to turn the warning level up higher, preferably to max.

Edit: And actually your entire program logic appears bizarre like you mixed and matched totally different strategies.
• 07-21-2008
kirksson
brick = prick
Your posts are really useless so stop posting replies. If my code is bizzare why in the world you're even bothering to spend your precious time on my code. Get lost before i use my Mr. T line.
• 07-21-2008
tabstop
Quote:

Originally Posted by kirksson
Your posts are really useless so stop posting replies. If my code is bizzare why in the world you're even bothering to spend your precious time on my code.

Because you asked him to? Hello?

Also, forgot to mention: to call a function, like lottery for instance, you need to put (stuff in parentheses) behind it, indicating what you want to pass to the function.

Edit: Oh, and his point was also that if your code is only that long, there's no need to attach it, because, well, it's only that long. Making people have to click, and click, and then click again just to read it is not to your advantage. (I mean, yes, I'm that bored, but a lot of people aren't.)
• 07-22-2008
MacGyver
Quote:

Originally Posted by kirksson
Your posts are really useless so stop posting replies.

I'll post wherever I wish on these forums without your permission and without your blessing, as I told you more than once when you PM'ed me multiple times with such complaints.

Quote:

Originally Posted by kirksson
If my code is bizzare why in the world you're even bothering to spend your precious time on my code.

If you won't put the effort into getting a decent grade, why take a programming course?

Quote:

Originally Posted by kirksson
Get lost before i use my Mr. T line.

Quote:

Originally Posted by kirksson
I hope that is not all you got! We are just warming up because " I pity you fool!" - (remeber that famous line.)

I was actually waiting when you will use religious remarks so you can call me a buss driver.
Why a bus driver ?
I am taking you to school son!

I don't mind you being an idiot entirely since it doesn't necessarily affect me if you mess your life up, but if you can't contain yourself in public, the mods might get upset and restrict your ability to post. I suggest you play nice in the sandbox, and work with those who are trying to help you.
• 07-23-2008
kirksson
Quote:

Originally Posted by MacGyver
I'll post wherever I wish on these forums without your permission and without your blessing, as I told you more than once when you PM'ed me multiple times with such complaints.

You are pathetic.

If you won't put the effort into getting a decent grade, why take a programming course?

Nunya - translate that

It looks like you need some new dose, you prick.

I don't mind you being an idiot entirely since it doesn't necessarily affect me if you mess your life up, but if you can't contain yourself in public, the mods might get upset and restrict your ability to post. I suggest you play nice in the sandbox, and work with those who are trying to help you.

No you are being an idiot and a total d-bag.
Let some others who know more than you collaborate with me since you are lousy looser.

Thank you, and you are welcome.
• 07-23-2008
MacGyver
/me shrugs.

Your call to respond that way, but I wouldn't be entirely surprised, however, if this topic ends up getting locked. :rolleyes: