A C Program Problem-Please Help! 
Author Message
 A C Program Problem-Please Help!

Please help! Can anyone tell me what I did wrong? The intended output is
like this:
<user input>
Whats the take on bagb?: 1
cc?:2
ppec?:3
pppp?:4
Another poll? Y
Whats the take on bagb?: 2
cc?:3
ppec?:4
pppp?:5
Another poll? N

<program output>
Value1=1
Value2=2
Value1=2
Value2=3
Value1=3
Value2=4
Value1=4
Value2=5

#include<stdio.h>

int fill(double[],double[],double[],double[],int);
void show(double[],int);

void main()
{
int size,k;
double bagb[20],cc[20],ppec[20],pppp[20];
size=fill(bagb,cc,ppec,pppp,20);

show(bagb,size);
show(cc,size);
show(ppec,size);
show(pppp,size);*/

Quote:
}

int fill(double bagb[],double cc[],double ppec[],double pppp[],int
maxsize)
{
int k=0;
char repeat;
do
{
printf("What was the take on BAGB?: ");
scanf("%i",&bagb[k]);
printf("CC?: ");
scanf("%i",&cc[k]);
printf("PPEC?: ");
scanf("%i",&ppec[k]);
printf("PPPP?: ");
scanf("%i",&pppp[k]);
printf("Another poll(Y/N)?");
scanf(" %c",&repeat);
k++;

Quote:
}while(repeat=='Y'||repeat=='y');
return k;
}

void show(double x[],int size)
{
int k;
for(k=0;k<size;k++)
printf("Value %i=%lf\n",k+1,x[k]);

Quote:
}




Fri, 07 Jan 2000 03:00:00 GMT  
 A C Program Problem-Please Help!



Quote:
>Please help! Can anyone tell me what I did wrong? The intended output is
>like this:

...

Quote:
>#include<stdio.h>

>int fill(double[],double[],double[],double[],int);
>void show(double[],int);

>void main()

main returns int, that should be:

int main()

or better still:

int main(void)

Quote:
>{
>int size,k;

k isn't used here.

Quote:
>double bagb[20],cc[20],ppec[20],pppp[20];
>size=fill(bagb,cc,ppec,pppp,20);

>show(bagb,size);
>show(cc,size);
>show(ppec,size);
>show(pppp,size);*/

There was no /* so this is a syntax error.

 return 0;   /* To generate a successful termination indiation */

Quote:
>}

>int fill(double bagb[],double cc[],double ppec[],double pppp[],int
>maxsize)
>{
>int k=0;
>char repeat;
>do
>{
>printf("What was the take on BAGB?: ");
>scanf("%i",&bagb[k]);

%i requires that you pass as the corresponding argument a pointer to an int.
You pass it a pointer to a double. You must decide which you want, if
an integer define bagb accordingly, if a double use %lf instead of %i.

Quote:
>printf("CC?: ");
>scanf("%i",&cc[k]);
>printf("PPEC?: ");
>scanf("%i",&ppec[k]);
>printf("PPPP?: ");
>scanf("%i",&pppp[k]);

Similarly for all of these.

Quote:
>printf("Another poll(Y/N)?");
>scanf(" %c",&repeat);
>k++;
>}while(repeat=='Y'||repeat=='y');
>return k;
>}

>void show(double x[],int size)
>{
>int k;
>for(k=0;k<size;k++)
>printf("Value %i=%lf\n",k+1,x[k]);

Just to confuse you there is no %lf conversion specifier for printf. For
double use %f (or %.0f if you don't want to output any decimal places).
%f works for float as well since in a variable argument list float
arguments get promoted automatically to double.

Quote:
>}



Please read responses in the newsgroup.

--
-----------------------------------------


-----------------------------------------



Fri, 07 Jan 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem #30 on http://cs.nmu.edu/programming/c/problems.htm

2. Need help on this programming problem ( PLEASE HELP!!!)

3. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

4. program problem, please HELP!!!

5. Problem with Program!!Please Help (AGAIN).

6. Please help-two problems with C program

7. HELP w/ C Programming Problem...PLEASE!!

8. A C program problem, Please help!

9. Please Beginner Help with C programming problem.

10. Please help beginner with programming problem

11. Problem in my program.....Please Help

12. Problem in my program (Please help!)

 

 
Powered by phpBB® Forum Software