-
Notifications
You must be signed in to change notification settings - Fork 0
/
computer space sizeof exercise
39 lines (32 loc) · 1.69 KB
/
computer space sizeof exercise
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
/*
A delivery company has hired you to manage their tracking services division. It is your job to store all of the currently used tracking codes in the company's database. These codes consist of either all integers, all decimal numbers, or all characters. The chief technology officer has warned you that the database is old and has limited space, so you want to determine how much memory the tracking codes will occupy before storing them. You decide to write a program to assist you in this process.
Your program should first read an integer number indicating how many tracking codes you plan on entering. Next, for each successive tracking code your program should read in the integer length of code followed by a space and then the type of code ('i' for integer, 'd' for decimal, or 'c' for character). Finally your program should print the total amount of space required to store all of the tracking codes (in bytes). If the user enters an incorrect type for any tracking number, the program should print 'Invalid tracking code type' and exit.
*/
#include <stdio.h>
int main() {
int numero,x, num, totalbytes;
char type;
char c = 'c';
char i = 'i';
char d = 'd';
int ammC=0;
int ammI=0;
int ammD=0;
scanf("%d", &numero);
for(x = 0; x < numero; x++){
scanf("%d %c",&num, &type);
if(type==c){
ammC = num * sizeof(char);
}else if(type==i){
ammI = num * sizeof(int);
}else if(type==d){
ammD = num * sizeof(double);
}else{
printf("Invalid tracking code type");
return(0);
}
}
totalbytes = ammC + ammI + ammD;
printf("%d bytes", totalbytes);
return(0);
}