Like Tree3Likes
  • 3 Post By stahta01

Help with Program

This is a discussion on Help with Program within the C Programming forums, part of the General Programming Boards category; This is my assignment and I was able to write the below code so far. But I'm getting theerrors. Please ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    3

    Help with Program

    This is my assignment and I was able to write the below code so far. But I'm getting theerrors. Please Help !

    This is the question:


    Write a program that first prompts users for their full names (store each first, middle, and last -
    in three separate character arrays), hours worked, hourly rates, and tax rates, and then displays
    taxes and net pay, using the appropriate dollars-and-cents print codes.
    Sample output:
    First Middle Last Hours-Worked Hourly-rate Tax-rate Taxes Net-pay
    ------ ------------- ------------ ----------- -------- ----- -------- ---------
    Jim V. Wrenn 40 $10.7 20% $85.6 $342.4







    Code:
    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include<conio.h>
    
    
    void main()
    
    
    
    
    {
    
    
    int i,j;
    
    
    
    
    printf(" Please enter the number of people \n\n");
    scanf("%d",&i);
    
    
    
    
    char fname[i][10],mname[i][10],lname[i][10]; // Strings for first name, middle  name, last name.
    
    
    float hours[i], hoursrate[i], taxes[i], netpay[i], taxrate[i];  //arrays for hours worked,$/hr,taxes...
    
    
    
    
    
    
    
    
    
    
    for(j=0;j<i;j++)
    {
    printf("Please enter First Name, Middle Name, Last Name, Number of Hours worked, Hourly pay, Tax Rate");
    scanf(" \n\n\n %s %s %s %f %f %f ", fname[j], mname[j], lname[j], &hours[j], &hoursrate[j], &taxrate[j]);  //Taking full name and work details
    }
    
    
    
    
    
    
    printf(" %8s %8s %8s %8s %8s %8s %8s %8s \n","fname","mname","lname","hours","$/hr","taxrate","taxes","pay");
    for(j=0;j<i;j++)
    {
    taxes[j]=(hours[j]*hoursrate[j])*(taxrate[j]/100); //calculating taxes for each person
    netpay[j]=(hours[j]*hoursrate[j])-taxes[j]; //calculating net pay
    
    
    printf(" %8s %8s %8s %8.2f %8.2f %8.2d %8.2f %8.2f \n",fname[j],mname[j],lname[j],hours[j],hoursrate[j],taxrate[j],taxes[j],netpay[j]);
    }
    
    
    
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > But I'm getting theerrors. Please Help !
    Well post them then.

    You'll need a modern compiler to compile the code you have. Older (C89 and earlier K&R-C) does NOT support mixed declarations, or variable length arrays.


    SourceForge.net: cpwiki
    Read the void main and indentation pages


    > #include<iostream>
    If you're writing C, then delete this line!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    3
    I'm getting the following errors:
    fname:unknown size
    cannot allocate an array of constant size 0

    I'm getting the same error(unknown size) for mname,lname,taxes,hours,hoursrate,netpay,taxrate.

    I'm using visual studio 2010. I've remove the iostream but getting the same errors.

    Thanks for the reply

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    Some examples

    Code:
    char (*fname)[10];
    float *hours;
    scanf("%d",&i);
    fname = malloc( i * sizeof(*fname) );
    hours = malloc( i * sizeof(*hours) );
    Three things you MUST do
    1. change void main to int main
    2. #include <stdlib.h>
    3. Make sure your source file is named something like prog.c (and NOT prog.cpp)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    3
    I've changed the code but I'm still getting these errors

    -a value type void* cannot be assigned to an entity of type char(*)[10].
    -a value type void* cannot be assigned to an entity of type "float*"

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    2,767
    Quote Originally Posted by pratheek238 View Post
    I've changed the code but I'm still getting these errors

    -a value type void* cannot be assigned to an entity of type char(*)[10].
    -a value type void* cannot be assigned to an entity of type "float*"
    Then try once more to make sure the file ends with .c instead of .cpp.

    If it still fails try using a real C Compiler; not, a C++ Compiler.
    Note: The above is stated with the idea you really want to program in C; since you posted in a C forum.

    Tim S.
    Last edited by stahta01; 05-30-2012 at 04:47 AM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2,767
    FYI: If you have never disabled the Windows default setting that hides the file extension; disable it now!

    Show Extensions :: Scott Granneman

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-16-2010, 11:17 AM
  2. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  3. Replies: 5
    Last Post: 08-17-2007, 12:43 AM
  4. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  5. making a program leave a msg for background program when it closes
    By superflygizmo in forum Windows Programming
    Replies: 2
    Last Post: 02-06-2006, 07:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21