Wandbox
SettingsLog
SettingsLog
Language
GitHubLogin
Ran/Viewed Log

Viewed less than a minute ago

UqnhRIWwHOMY4Mol

C gcc 12.1.0

Created at 1 minute ago

Created by anonymous

Author

anonymous

1 minute ago

Language

C

Compiler

gcc 12.1.0

Options
Warnings
C11
no pedantic
セオライド・テクノロジー㈱株式会社フィックスターズ

Author

anonymous

1 minute ago

›
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//#include <cs50.h>
#include <ctype.h>
#include <stdio.h>

int get_int(const char* x, ...) {
int a;
scanf("%d", &a);
return a;
}

char get_char(const char* x) {
return getchar();
}

float calc_hours(int hours[], int weeks, char output);

int main(void)
{
int weeks = get_int("Number of weeks taking CS50: ");
int hours[weeks];

for (int i = 0; i < weeks; i++)
{
hours[i] = get_int("Week %i HW Hours: ", i);
}

char output;
do
{
output = toupper(get_char("Enter T for total hours, A for average hours per week: "));
}
while (output != 'T' && output != 'A');

printf("%.1f hours\n", calc_hours(hours, weeks, output));
}

// TODO: complete the calc_hours function
float calc_hours(int hours[], int weeks, char output)
{
float final_hours = 0;

//TODO: Write conditional for 'T'
if (output == 'T')
{
for (int j = 0; j < weeks; j++)
{
final_hours = final_hours + hours[j];
}
return final_hours;
}
//TODO: Write conditional for 'A'
if (output == 'A')
{
for (int k = 0; k < weeks; k++)
{
final_hours = (final_hours + hours[k]) / weeks;
}
return final_hours;
}
}
›
9
1
3 1 2 3 T
$ gcc prog.c -Wall -Wextra -std=c11
prog.c: In function 'get_int':
prog.c:5:25: warning: unused parameter 'x' [-Wunused-parameter]
    5 | int get_int(const char* x, ...) {
      |             ~~~~~~~~~~~~^
prog.c: In function 'get_char':
prog.c:11:27: warning: unused parameter 'x' [-Wunused-parameter]
   11 | char get_char(const char* x) {
      |               ~~~~~~~~~~~~^
prog.c: In function 'calc_hours':
prog.c:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
6.0 hours
Exit Code:
0
セオライド・テクノロジー㈱株式会社フィックスターズ