Im making a cmd line based tempature converter program, and it needs to use doubles for more accurate tempature readings. I need to convert argv[1] to a double so it will work in the formula.
The code should be right, ignore all the messed up stuff in this piece of code, this is just my drawing board.
#include <iostream.h>
#include <ctype.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char* argv[])
{
char sys;
double deg, xdeg;
int crap;
if (argc != 3) {
cout << "Example: dex.exe 80 f\n"
<< "Example: dex.exe 27 c\n\n";
return 0;
}
// char(argv[2]);
crap = atoi(argv[1]);
// cout << deg << argv[2];
deg = crap;
// deg = argv[1];
// sys = argv[2];
// sys = toupper(argv[2]);
// if (sys != 'C' && 'F') {
// cout << "Example: dex.exe 80 f\n"
// << "Example: dex.exe 27 c\n\n";
// return 0;
// }
switch (sys) {
case 'F':
xdeg = (deg - 32.) * 5./9.;
cout << xdeg << "C\n";
break;
case 'C':
xdeg = 32. + 9./5. * deg;
cout << xdeg << "F\n";
break;
}
return 0;
}
The code should be right, ignore all the messed up stuff in this piece of code, this is just my drawing board.
#include <iostream.h>
#include <ctype.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char* argv[])
{
char sys;
double deg, xdeg;
int crap;
if (argc != 3) {
cout << "Example: dex.exe 80 f\n"
<< "Example: dex.exe 27 c\n\n";
return 0;
}
// char(argv[2]);
crap = atoi(argv[1]);
// cout << deg << argv[2];
deg = crap;
// deg = argv[1];
// sys = argv[2];
// sys = toupper(argv[2]);
// if (sys != 'C' && 'F') {
// cout << "Example: dex.exe 80 f\n"
// << "Example: dex.exe 27 c\n\n";
// return 0;
// }
switch (sys) {
case 'F':
xdeg = (deg - 32.) * 5./9.;
cout << xdeg << "C\n";
break;
case 'C':
xdeg = 32. + 9./5. * deg;
cout << xdeg << "F\n";
break;
}
return 0;
}