🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #718

Re: please help me with this problem

#718
From: bluemonsters
Date: Fri, 23 Jul 1999 00:00
71 lines
3775 bytes
Aside from the scanf is evil problem, you also have a problem with array
addressing.  Note that in C, the first
address starts at 0 not 1.  So the line

char marital_stat[5];

sets up an array with 5 elements that must be addressed as marital_stat[0]
through marital_stat[4].  You should check the loop in getting_the_info().
If you try to access marital_stat[5] bad things will happen to your helpless
program.

cyberian bear wrote in message ...
>i have written program which collects marital status and income of 5 people
>and computes their tax. in this prog i had to use a for loop and array.
>basically i got most of it but when i execute it asks me for marital status
>of first person than his income tehn it skips over marital status of second
>person and goes straight to his income, the same happend with 3rd 4th 5th
>person. if any1 could please tell me wehre my mistake is i would be very
>greatefull to You
>Paul
>
>/*Filename:tax604.c
>program which calculates taxes paid for 5 people */
> #include<stdio.h>
> int index;
> char marital_stat[5];
> float income[5];
>
> main()
> {
> introduction();
> getting_the_info();
> }
>
>
> /*The following are functions used in this program*/
>/*-------------------------------------------------------------------------
*
>/
>introduction()
>{printf("\t\t\t\tTAX PROGRAM\n\t\t\t   BY \n\n");
>printf("\t\t\t\tINSTRUCTIONS:\n");
>printf("\t\t     1.ENTER ANNUAL SALARY FOR A PERSON.\n");
>printf("\t\t     2.ENTER MARITAL STATUS OF A PERSON.\n");
>printf("\t\t\t   3.REPEAT WHEN PROMPTED.\n\n");
> return;
> }
>
>/*------------------------------------------------------------------------*
/
>getting_the_info()
>{ index=1;
>for (index=1; index<=5; index++)
>{printf("\nPlease enter the marital status of person # ");
>printf("%d ==>", index);
> scanf("%c", &marital_stat[index]);
>printf("\nPlease enter income of person # ");
>printf("%d ==>", index);
>scanf("%f", &income[index]);
>}
> return;
>}
>
>--
>http://www.geocities.com/Pentagon/Barracks/5529/frame-controls.html
>
>--
>comp.lang.c.moderated - moderation address: clcm@plethora.net

-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net
Technical Details
Message-ID: <clcm-19990723-0002@plethora.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <clcm-19990714-0004@plethora.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114a87,488b53d56236ec72
X-Google-Attributes: gid114a87,public
X-Google-Thread: 10f67c,488b53d56236ec72
X-Google-Attributes: gid10f67c,public
X-Google-Thread: 114592,488b53d56236ec72
X-Google-Attributes: gid114592,public
X-Google-Thread: 100850,488b53d56236ec72
X-Google-Attributes: gid100850,public
X-Google-Thread: f4614,488b53d56236ec72
X-Google-Attributes: gidf4614,public
X-Google-Thread: 1111a3,488b53d56236ec72
X-Google-Attributes: gid1111a3,public
X-Google-Thread: 1014db,488b53d56236ec72
X-Google-Attributes: gid1014db,public
X-Google-Thread: 106434,488b53d56236ec72
X-Google-Attributes: gid106434,public
From: "bluemonsters" <bluemonsters@erols.com>
Subject: Re: please help me with this problem
Date: 1999/07/23
Message-ID: <clcm-19990723-0002@plethora.net>
X-Deja-AN: 504531966
X-Old-trace: 5IQl8gsHeY4vsrxR1VzE0spiyoLskZpDTAZFFjkaDV9reQsQFu0Sow==
Sender: news <news@autumn.news.rcn.net>
Approved: clc@plethora.net
References: <clcm-19990714-0004@plethora.net>
X-Mimeole: Produced By Microsoft MimeOLE V4.72.3110.3
X-Complaints-To: abuse@plethora.net
X-Trace: ptah.visi.com 932763133 205.166.146.1 (Fri, 23 Jul 1999 15:52:13 CDT)
X-Old-complaints-to: abuse@rcn.com
NNTP-Posting-Date: Fri, 23 Jul 1999 15:52:13 CDT
Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c,comp.lang.c.moderated,comp.lang.objective-c,fj.comp.lang.c,fj.lang.c,it.comp.lang.c,pl.comp.lang.c,relcom.comp.lang.c-c++
Originator: clcm@plethora.net (Comp Lang C'Moderated)