Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- void die(const char *message)
- {
- if(errno) {
- perror(message);
- } else {
- printf("ERROR: %s\n", message);
- }
- exit(1);
- }
- int main(int argc, char *argv[]) {
- const double yins = 0.067;
- const double siny = 14.91;
- if(argc < 2) die("USAGE: <currency option> <value to convert>");
- char curr = argv[1][0];
- char *ammount_str = argv[2];
- double ammount;
- sscanf(ammount_str, "%lf", &ammount);
- double converted;
- if(curr == 'y') {
- converted = ammount * siny;
- printf("%f SEK is equal to %f yen.\n", ammount, converted);
- } else if(curr == 's') {
- converted = ammount * yins;
- printf("%f yen is equal to %f SEK.\n", ammount, converted);
- } else die("Invalid currency option.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement