nanode
01-24-2001, 02:21 AM
I was playing around w/ some real basic C++ stuff and thought I'd make a simple calc. proggie that takes the values as args. Problem is, even when I cast the args as ints, the value is all whacked.
//TireCalc.cpp
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
if(argc != 4) {
cout << "Usage: " << argv[0] << " [width]" << " [profile] " << " [rim]" << endl;
}
else {
int width = (int)argv[1];
int profile = (int)argv[2];
int rim = (int)argv[3];
cout << " width: " << width << " profile: " << profile << " rim: " << rim << endl;
double wallHeightInch = (width / 25.4) * (.01 * profile);
double totalHeightInch = (wallHeightInch * 2) + rim;
cout << "Total wheel diameter: " << totalHeightInch << endl;
}
}
running it shows this:
nanode@stout:~/playcode$ tc 215 70 14
width: -1073743860 profile: -1073743856 rim: -1073743853
Total wheel diameter: 9.07815e+14
nanode@stout:~/playcode$
where are those longs negative ints coming from? I'm obviously lazy and spoiled from using Java all this time.
Thanks for your help.
//TireCalc.cpp
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
if(argc != 4) {
cout << "Usage: " << argv[0] << " [width]" << " [profile] " << " [rim]" << endl;
}
else {
int width = (int)argv[1];
int profile = (int)argv[2];
int rim = (int)argv[3];
cout << " width: " << width << " profile: " << profile << " rim: " << rim << endl;
double wallHeightInch = (width / 25.4) * (.01 * profile);
double totalHeightInch = (wallHeightInch * 2) + rim;
cout << "Total wheel diameter: " << totalHeightInch << endl;
}
}
running it shows this:
nanode@stout:~/playcode$ tc 215 70 14
width: -1073743860 profile: -1073743856 rim: -1073743853
Total wheel diameter: 9.07815e+14
nanode@stout:~/playcode$
where are those longs negative ints coming from? I'm obviously lazy and spoiled from using Java all this time.
Thanks for your help.