I writing a program to read several data lines in from a file then using functions to process the data. One of the function is giving me an error that i can't figure out.
The following code works fine with "1/2". However there is a case when the '/' sign is in the 3 position "1 1/2". So i thought i'd just add another if statement.
string temp;
int a, b;
string ch4 = "/";
if (code4.substr(1,1) == ch4)
{
temp = code4.substr(0,1);
a = atoi(temp.c_str());
temp = code4.substr(2,1);
b = atoi(temp.c_str());
double k = double(a)/b;
cout << setw(15) << left << "Visibility:" << k << " statute miles" << endl;
}
else
{
temp = code4.substr(0,2);
cout << setw(15) << left << "Visibility:" << temp << " statute miles" << endl;
}
This code doesn't work with added if statement.
string temp;
int a, b;
string ch4 = "/";
if (code4.substr(1,1) == ch4)
{
temp = code4.substr(0,1);
a = atoi(temp.c_str());
temp = code4.substr(2,1);
b = atoi(temp.c_str());
double k = double(a)/b;
cout << setw(15) << left << "Visibility:" << k << " statute miles" << endl;
}
if (code4.substr(3,1) == ch4)
{
temp = code4.substr(0,1);
a = atoi(temp.c_str());
temp = code4.substr(2,1);
b = atoi(temp.c_str());
temp = code4.substr(4,1);
int c = atoi(temp.c_str());
double k = a + double(b)/c;
cout << setw(15) << left << "Visibility:" << k << " statute miles" << endl;
}
else
{
temp = code4.substr(0,2);
cout << setw(15) << left << "Visibility:" << temp << " statute miles" << endl;
}
I get "application has requested the Runtime to terminate it in an unusual way."
Where is my error and how can i fix it?
TIN
Soccerace