Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Programming with Viope Tool

1. ## 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......

• 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)

• Originally Posted by Fou-Lu
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
•