Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2012, 12:42 PM   PM User | #1
Viope
New to the CF scene

 
Join Date: Sep 2012
Location: Helsinki-Finland
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Viope is an unknown quantity at this point
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
Viope is offline   Reply With Quote
Old 09-05-2012, 03:59 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Viope (09-07-2012)
Old 09-07-2012, 02:10 PM   PM User | #3
Viope
New to the CF scene

 
Join Date: Sep 2012
Location: Helsinki-Finland
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Viope is an unknown quantity at this point
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.
Viope is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:47 AM.


Advertisement
Log in to turn off these ads.