C/C++
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs C/C++

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old July 5th, 2008, 11:39 PM
Bert
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Problem 77: Greedy Gift Givers

Why doesn't it do the problem correctly now?

/*
ID: albert.4
LANG: C
TASK: gift1
*/

#include <stdio.h>

#define MAXNAMELEN 14

main()
{
struct friend {
int money, ngifts; /* no. gifts */

char name[MAXNAMELEN];
};

int NP; /* no. people */

FILE* in = fopen("gift1.in" , "r");
FILE* out = fopen("gift1.out", "w");

fscanf(in, "%d", &NP);

struct friend f[NP];

int i = 0;

for (; i < NP; i++)
{
fscanf(in, "%s", f[i].name);
}

/* Until input tells us how much each friend has (later in this
prog), they're all broke */
i = 0;

for (; i < NP; i++)
{
f[i].money = 0;
}

char temp[MAXNAMELEN];

for (i = 0; i < NP; i++)
{
fscanf(in, "%s", temp);

if (strcmp(f[i].name, temp) == 0)
{
int init; /* initial amount of money */

fscanf(in, "%d %d", &init, &f[i].ngifts);

f[i].money = init * -1; /* init is given to people */

if (f[i].ngifts != 0)
{
f[i].money += init % f[i].ngifts;
}

int amteachpersongets = 0;

if (f[i].ngifts != 0)
{
int amteachpersongets = init / f[i].ngifts;
}

int j = 0;

char temp2[MAXNAMELEN];

for (; j < f[i].ngifts; j++)
{
fscanf(in, "%s", temp2);

int k = 0;

for (; k < NP; k++)
{
if (strcmp(f[k].name, temp2) == 0)
{
f[k].money += amteachpersongets;
break;
}
}
}
}
}

for (i = 0; i < NP; i++)
{
fprintf(out, "%s %d\n", f[i].name, f[i].money);
}

exit(0);
}

Reply With Quote
  #2  
Old July 7th, 2008, 06:19 AM
Willem
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Problem 77: Greedy Gift Givers

Bert wrote:
) Why doesn't it do the problem correctly now?

What is the incorrect output then, and what should the correct output be ?


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something
No I'm not paranoid. You all think I'm paranoid, don't you !
#ET

Reply With Quote
Reply

Viewing: Web Development Archives FAQs C/C++ > Problem 77: Greedy Gift Givers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT