Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Location
    Helsinki-Finland
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Programming with Viope Tool

    Guys..I am studying with Viope Tool and have this question to answer...Really need some help...
    Write a program that calculates the number of hours worked within a specific period and prints the total number of hours, the average length of a day and an itemisation of the hours entered. First, the program must ask how many days of working hours shall be entered (max 30 days). After this, the program asks for the daily working hours. The program output shall have one decimal place of precision.

    Hint:
    It is easiest to implement the program using an array with 30 elements.
    Example output
    The program calculates the total hours worked during
    a specific period and the average length of a day.

    How many days:5
    Enter the working hours for day 1:8.75
    Enter the working hours for day 2:6.0
    Enter the working hours for day 3:5.5
    Enter the working hours for day 4:8.0
    Enter the working hours for day 5:7.5

    Total hours worked: 35.8
    Average length of day: 7.2
    Hours entered: 8.8 6.0 5.5 8.0 7.5

    After running this code
    #include <stdio.h>
    2:
    3: int main(void)
    4: {
    5: float total = 0, hours[30];
    6: int i;
    7:
    8: printf("The program calculates the total hours worked during\n");
    9: printf("a specific period and the length of a day.\n\n");
    10:
    11: printf("How many days:");
    12: scanf("%d", &days);
    13:
    14: for(i=0;i<days;i++){
    15: printf("Enter the hours for day %d:",i+1);
    16: scanf("%f",&hours[i]);
    17: total += hours[i];
    18: }
    19:
    20: printf("\nTotal hours worked: %.1f\n", total);
    21: printf("Average length of day: %.1f\n", total/days);
    22: printf("Hours entered: ");
    23:
    24: for(i=0;i<days;i--){
    25: printf("%.1f ", hours[i]);
    26: }
    27: printf("\n");
    28:
    29: return 0;
    30: }

    am getting this feedback
    code.c: In function ‘main’:

    code.c:12: error: ‘days’ undeclared (first use in this function)

    code.c:12: error: (Each undeclared identifier is reported only once

    code.c:12: error: for each function it appears in.)

    Can someone help me out please......
    Last edited by Viope; 09-05-2012 at 12:46 PM. Reason: I am new here...and am not sure if I have posted this to the C programming envirinment

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't know what viope is, but this this definitely C code, not python. Moving to computer programing forum.

    The error is exactly as it states. The "days" variable hasn't been declared anywhere. Its an int, so just predeclare it in with the int i, or give it its own datatype declaration.

  • Users who have thanked Fou-Lu for this post:

    Viope (09-07-2012)

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Location
    Helsinki-Finland
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    I don't know what viope is, but this this definitely C code, not python. Moving to computer programing forum.

    The error is exactly as it states. The "days" variable hasn't been declared anywhere. Its an int, so just predeclare it in with the int i, or give it its own datatype declaration.
    thanks a lot for the info..I will try this and contact you if I encounter any issue. Viope is the platform for teaching and learning programming that my school uses.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •