-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrect2.c
126 lines (113 loc) · 2.4 KB
/
correct2.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "ptuclib.h"
/* Program useless */
/* Type declaration: */
typedef char* string;
/* Variable declaration: */
int i, j;
string item;
/* Function declaration: */
double powerTo(double number, int power)
{
double result;
result = 1;
if (power > 0)
{
for (i = 0; i <= power - 1; i++) result = result * number;
}
else if (power < 0)
{
for (i = 0; i >= power + 1; i--) result = (double) result / number;
}
else result = 1;
return result;
}
void printShoppingList(int i, string shoppingList[1000], double priceList[1000], double sum)
{
writeString("\n\nShopping list:\n");
for (j = 0; j <= i - 1; j++)
{
writeInteger(j + 1);
writeString(":\tItem:\t\"");
writeString(shoppingList);
writeString("\"\n\tPrice:\t");
writeReal(priceList[j]);
writeString("€\n\n");
shoppingList = shoppingList + 1;
}
writeString("\nTotal Price: ");
writeReal(sum);
writeString("€\n");
}
void shopping()
{
string shoppingList[1000];
double priceList[1000];
string tempString;
double sum;
int exit;
i = 0;
sum = 0;
do
{
writeString("Give me an item: ");
scanf("%s", &tempString);
shoppingList[i] = tempString;
writeString("\n");
writeString("Give me its price in €: ");
scanf("%lf", &priceList[i]);
writeString("\n");
sum = sum + priceList[i];
i = i + 1;
label:writeString("\nPress 0 to exit ot 1 to continue: ");
scanf("%d", &exit);
writeString("\n");
if (exit != 1 && exit != 0)
{
writeString("Wrong input!\n");
goto label;
}
}
while (!(exit == 0));
printShoppingList(i,shoppingList,priceList,sum);
}
void menu()
{
double (*power)(double x, int y);
int choice, temp2;
double temp1;
lbl:choice = -1;
writeString("\nMenu:\nSelect equivalent option:\n\t1: Power operation\n\t2: Make a shopping list!\n\t3: Exit\n\nChoice: ");
lbl2:scanf("%d", &choice);
if (choice > 3 || choice < 1)
{
writeString("\nWrong choice! Try again: ");
goto lbl2;
}
if (choice == 1)
{
writeString("\nGive me the base(positive or negative number): ");
scanf("%lf", &temp1);
writeString("\nGive me the power(positive or negative integer): ");
scanf("%d", &temp2);
writeString("\n");
writeReal(temp1);
writeString(" ^ ");
writeInteger(temp2);
writeString(" = ");
power = powerTo;
writeReal(power(temp1,temp2));
writeString("\n");
goto lbl;
}
else if (choice == 2)
{
shopping();
goto lbl;
}
else writeString("\nHope to see you again!\n");
}
/* Main: */
int main() {
menu();
return 0;
}