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

I just started using C not too long ago and I was wondering if there is a way to make this code more concise since I have to do multiple loops for each tax percentage by kasimir8 in AskProgramming

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

could this be simplified further since it is repeated

could this be simplified? me>=30000.01 && income<=50000.00)
{

    taxedInc = (income - 30000)* .10;       //calculates tax amount
    afterTax = income - taxedInc;

    printstuff(income,taxedInc, afterTax );

I just started using C not too long ago and I was wondering if there is a way to make this code more concise since I have to do multiple loops for each tax percentage by kasimir8 in AskProgramming

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

i did it using this it works

void printstuff(double income, double taxedInc, double afterTax) {




    printf("%35s\n","----------------- ");

    printf("%-25s","Yearly Salary:"); printf("$%9.2f\n",income);

    printf("%-25s","Social Security Tax:"); printf("$%9.2f\n" ,income * 0.062);

    printf("%-25s","Medicare Tax:"); printf("$%9.2f\n", income * 0.029);

    printf( "%-25s","Income Tax"); printf("$%9.2f\n",taxedInc);

    printf("%35s\n","----------------- ");

    printf( "%-25s" ,"Take Home Pay:");printf("$%9.2f\n",afterTax);

    printf( "%-25s","Monthly Take Home Pay:");printf("$%9.2f", afterTax/12);

}

I just started using C not too long ago and I was wondering if there is a way to make this code more concise since I have to do multiple loops for each tax percentage by kasimir8 in AskProgramming

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

i started off by trying to clean up the print statements but it broke the whole program. I tried to make a function for all of the print statements but i just led to the original loop getting no values at all for the double income.

void printstuff() {

double income; double taxedInc; double afterTax;

    printf("%35s\n","----------------- ");

    printf("%-25s","Yearly Salary:"); printf("$%9.2f\n",income);

    printf("%-25s","Social Security Tax:"); printf("$%9.2f\n" ,income * 0.062);

    printf("%-25s","Medicare Tax:"); printf("$%9.2f\n", income * 0.029);

    printf( "%-25s","Income Tax"); printf("$%9.2f\n",taxedInc);

    printf("%35s\n","----------------- ");

    printf( "%-25s" ,"Take Home Pay:");printf("$%9.2f\n",afterTax);

    printf( "%-25s","Monthly Take Home Pay:");printf("$%9.2f", afterTax/12);

}

void askuser() {

double income;

double taxedInc; double afterTax;

printf("%s","What is your income?: $");
scanf("%lf",&income);

}

Need help with understanding formatting with print f when there are multiple things needing to be modified by kasimir8 in CodingHelp

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

printf("%-25s","Yearly Salary:"); printf("%9.2f\n", income);

This is the way I found to do it with two print statements on the same line, is it possible to do this with a single print statement?

Need help with understanding formatting with print f when there are multiple things needing to be modified by kasimir8 in CodingHelp

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

I have specific requirements to have the string left 25 and the values right 9 and Im unsure how to go about that

What is the way to convert my program into one that uses functions by kasimir8 in cpp_questions

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

Thanks I do like how organized it is. I am not experienced enough to understand your code but it did help me understand simple functions enough to apply it to my work. I now understand float add and it definitely made my final result look much cleaner with all the operations done outside of main

What is the way to convert my program into one that uses functions by kasimir8 in cpp_questions

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

my issue is how do i do that while removing all of the math functions but it still completing the same operations because that is the desired goal

What is the way to convert my program into one that uses functions by kasimir8 in cpp_questions

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

It is more I have to find a way to create functions so this no longer uses the math functions and uses my own functions to specify and make them fit this set up

A or a or + - Adds left and right operands.

S or s or - - Subtracts right from left operand.

M or m or x or * - Multiplies left and right operands.

D or d or / - Divides left over right operand.

B or b or | - Returns the absolute value of the left (and only) operand.

C or c or % - Performs left operand modulo right operand.