I'm new to C++ and development in general. Frankly, I have no idea what is going on. I'm just trying to display a string on one line, but the program is giving me a confusing error.
I would really appreciate any help.
#include <iostream> #include <iomanip> #include <string> using namespace std; // This program calculates and displays to user int main() { // Constants are state and county taxes. const float STATE_TAX_RATE = 0.04, COUNTY_TAX_RATE = 0.02; // float variables are : float gross_sales = 0, net_sales = 0, county_tax_payment = 0, state_tax_payment = 0, total_tax_payment = 0; // string variable string month; // integer variable int year; // Get month, year, and sales information from user cout << "For what month is this? (Please type the name of the month.)\nAnswer: "; getline(cin, month); cout << "For what year?\nAnswer: "; cin >> year; cout << "How much was total sales at the register?\nAnswer: "; cin >> gross_sales; // Calculate the net income net_sales = (gross_sales)/(1 + STATE_TAX_RATE + COUNTY_TAX_RATE); // Calculate total taxes paid. total_tax_payment = (gross_sales - net_sales); // cout << total_tax_payment; // output test // Calculate total state taxes paid. state_tax_payment = (total_tax_payment * (2.0/3.0)); // cout << state_tax_payment; //output test // Calculate county taxes paid. county_tax_payment = (total_tax_payment * (1.0/3.0)); //Display the information cout << "Month: " << month << " " << year << endl; cout << "--------------------" << endl; cout << "Total collected:\t $" << fixed << setw(9) << setprecision(2) << right << gross_sales << endl; cout << "Sales: \t\t\t\t $" << fixed << setw(9) << setprecision(2) << right << net_sales << endl; cout << "County Sales Tax:\t $" << fixed << setw(9) << setprecision(2) << right << county_tax_payment << endl; cout << "State Sales Tax:\t $" << fixed << setw(9) << setprecision(2) << right << state_tax_payment << endl; cout << "Total Sales Tax:\t $" << fixed << setw(9) << setprecision(2) << right << total_tax_payment << endl; return 0; } The output looks like this:
For what month is this? (Please type the name of the month.)
Answer: March
For what year?
Answer: 2008
How much was total sales at the register?
Answer: 26572.89
(lldb)
At "(lldb)" The program just stops... and Xcode indicates something I don't understand on "cout << "Month: " << month << " " << year << end;", telling where an issue is, then a lot of complex debugging info. The indicator is green colored.
Thanks again for any help!!!
endlinstead ofend(note the last letter)?state_tax_payment = net_sales / state_tax_payment;, you are dividing a non-initialized variablestate_tax_payment.1/3is zero (remainder one). You don't want integer division. Perhaps you want1.0/3.0and2.0/3.0?