-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab6.c
56 lines (45 loc) · 1.3 KB
/
lab6.c
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
#include <stdio.h>
int SumInts(int target)
{
FILE *inp;
inp = fopen("MyDataF.dat", "r");
int finalSum = 0, n;
while (!feof(inp)) // O(n^2)
{
fscanf(inp, "%d", &n);
if (n >= target)
{
finalSum += n;
}
}
fclose(inp);
return finalSum;
}
void Credit(int quarter, int dime, int nickel, int penny, int *dollars, int *cents)
{ // O(1)
int totalCash = 0;
totalCash = quarter * 25 + dime * 10 + nickel * 5 + penny;
*dollars = totalCash / 100;
*cents = totalCash % 100;
}
int main()
{
// Problem 1
int targetValue;
printf("Find the sum of all values above what threshold?\n");
scanf("%d", &targetValue);
printf("The sum of all values >= %d was found to be %d\n", targetValue, SumInts(targetValue));
// Problem 2
int quarter, dime, nickel, penny, dollars, cents;
char yesOrNo = 'y';
while (yesOrNo == 'y')
{
printf("Enter coins info (Quarter, Dime, Nickel, Penny): \n");
scanf("%d %d %d %d", &quarter, &dime, &nickel, &penny);
Credit(quarter, dime, nickel, penny, &dollars, ¢s);
printf("Coin Credit:\nDollars: %d\nChange: %d cents\n", dollars, cents);
printf("Do you want to continue (y or n)? ");
scanf(" %c", &yesOrNo);
}
return 0;
}