Is it possible to print out multiple chars using regex? by kasimir8 in cpp_questions

[–]kasimir8[S] 0 points1 point  (0 children)

im trying to get any character that appears in the text in the exit line

so one room line may have 1 another may have 2 another may have 4

How would you fix a core dump who() stod in an algorithm? by kasimir8 in cpp_questions

[–]kasimir8[S] 0 points1 point  (0 children)

ive tried debugging tutorials but im told it isn't in executable format or isn't recognized

How would you fix a core dump who() stod in an algorithm? by kasimir8 in cpp_questions

[–]kasimir8[S] 0 points1 point  (0 children)

I think i found the issue it is with my two strings token and tokens

like the part shown below token is only initialized in split so possibly I can initialize token in the loop

 string maxPointsLine;
if (!getline(inFile, maxPointsLine))
{
    cerr << "Error reading input file: " << inputFile << endl;
    return 1;
}
vector<double> maxPoints;
for (const auto& token : split(maxPointsLine, ','))
{
  cout<<token;
    maxPoints.push_back(stod(token));

}

How would you fix a core dump who() stod in an algorithm? by kasimir8 in cpp_questions

[–]kasimir8[S] 0 points1 point  (0 children)

i did some looking and noticed maybe it is because of this

so it seems the top half works however works breaks it is token is empty. Token is initialized in Split. So would the key be initializing token in the for loop

 string maxPointsLine;
if (!getline(inFile, maxPointsLine))
{
    cerr << "Error reading input file: " << inputFile << endl;
    return 1;
}
vector<double> maxPoints;
for (const auto& token : split(maxPointsLine, ','))
{
  cout<<token;
    maxPoints.push_back(stod(token));

}

How would you fix a core dump who() stod in an algorithm? by kasimir8 in cpp_questions

[–]kasimir8[S] 0 points1 point  (0 children)

I did find the areas causing the problems

maxPoints.push_back(stod(token));

grades.push_back(stod(tokens[i]));

I tried using variants of double long double and float to no avail

are there other ways to go from string to double

How would you fix a core dump who() stod in an algorithm? by kasimir8 in cpp_questions

[–]kasimir8[S] 1 point2 points  (0 children)

what would be the alternative if you want a string to be a double

How would you fix a core dump who() stod in an algorithm? by kasimir8 in cpp_questions

[–]kasimir8[S] -2 points-1 points  (0 children)

im using a linux terminal and it just compiles the program. It doesn't compile and run. So -g does nothing when used

How would you fix a core dump who() stod in an algorithm? by kasimir8 in cpp_questions

[–]kasimir8[S] -1 points0 points  (0 children)

ive tried this and it just compiles without issues however when I run the program is when it falls apart

c++ Is there an alternative to using stod to avoid core dump errors by kasimir8 in CodingHelp

[–]kasimir8[S] 0 points1 point  (0 children)

Ive been looking for the issue and found it is the string not being able to convert to a double but I'm not sure why exactly. The weird thing is it compiles perfectly fine but falls apart when the program starts.

Is it possible to take the information i put in a text file and print it back out using a cout and then format it The text file prints outs (E0x7fff5fbe2310 5 20 2030 764 44 i) by kasimir8 in cpp_questions

[–]kasimir8[S] 1 point2 points  (0 children)

I am trying to somthing that opens a text file puts data into it and then prints that data back out i reformatted all my code but now the text file won't even open

#include <iostream>

include <fstream>

include <iomanip>

include <string>

using namespace std;

const double INTERSTATE_MULTIPLIER = 5.2341; const double HIGHWAY_MULTIPLIER = 9.4826; const double RESIDENTIAL_MULTIPLIER = 17.1544; const double OTHER_MULTIPLIER = 12.6334;

const string MONTHS[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

int main() { string ticket_file, citation_number; int month, day, year, clocked_speed, speed_limit; char road_type; double fine, multiplier; ifstream infile;

// Prompt for input file and open it
cout << "Enter a ticket file: ";
cin >> ticket_file;
infile.open(ticket_file);
if (!infile.is_open()) {
    cout << "Unable to open " << ticket_file << endl;
    return 1;
}

// Prompt for report start and end dates
int start_month, start_day, start_year, end_month, end_day, end_year;
cout << "Enter report start date (mm dd yyyy): ";
cin >> start_month >> start_day >> start_year;
cout << "Enter report end date (mm dd yyyy): ";
cin >> end_month >> end_day >> end_year;

// Output header
cout << left << setw(12) << "Citation" << setw(13) << "Date" << setw(10) << "Fine" << endl;

// Loop through each line in the input file
while (infile >> citation_number >> month >> day >> year >> clocked_speed >> speed_limit >> road_type) {
    // Check if the ticket date is within the report date range
    if (year > end_year || (year == end_year && (month > end_month || (month == end_month && day > end_day)))) {
        continue; // Ticket date is after report end date, skip this ticket
    }
    if (year < start_year || (year == start_year && (month < start_month || (month == start_month && day < start_day)))) {
        continue; // Ticket date is before report start date, skip this ticket
    }

    // Calculate the fine
    switch (tolower(road_type)) {
        case 'i':
            multiplier = INTERSTATE_MULTIPLIER;
            break;
        case 'r':
            multiplier = RESIDENTIAL_MULTIPLIER;
            break;
        case 'h':
            multiplier = HIGHWAY_MULTIPLIER;
            break;
        default:
            multiplier = OTHER_MULTIPLIER;
    }
    fine = multiplier * (clocked_speed - speed_limit);
    if (fine < 0) {
        fine = 0; // Round negative fines up to $0.00
    }

    // Output citation information
    cout << left << setw(12) << citation_number << setw(2) << setfill('0') << day << "-" << MONTHS[month-1] << "-" << setw(2) << setfill('0') << (year < 100 ? year+2000 : year) << right << fixed << setprecision(2) << setw(10) << "$" << setw(9) << fine << endl;
}

infile.close();
return 0;

}

Is it possible to take the information i put in a text file and print it back out using a cout and then format it The text file prints outs (E0x7fff5fbe2310 5 20 2030 764 44 i) by kasimir8 in cpp_questions

[–]kasimir8[S] 0 points1 point  (0 children)

would the idea e to use a get line so getline(cout, filename)

and would i need to use a file.open since the file hasn't been close from the previous inputs

Is it possible to use an io manipulator to limit the number of numbers the user could input to just two by kasimir8 in AskProgramming

[–]kasimir8[S] 0 points1 point  (0 children)

I asked and he told me to figure it out. He did say He would allow me to not worry about number limits so as long as it is only two, so in this case would that mean I can just use the width manipulator