So i am very new to programming and C++. This little simple program is my second one and I'm in need of a little assistance. Below is my code followed by the output that I am getting and what I want it to look like. If anyone can point me in the right direction, or let me know how to change this it would be much appreciated.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
double propValue, //Property Value
assessment, //Assessment
srAssessment, //Sr Assessment
taxRate, //Tax rate
annualPropTax, //Annual Property tax
quarterlyTax; //Quarterly Tax
string name;
const double EXEMPT = 5000, //shows the total after exemption
QUARTER = 4, //represents the amount of quarters in a year
TAXPERHUNDRED = 0.01, //represents tax rate for every $100
SIXTYPERCENT = 0.6; //Represents the tax based on 60% of original value
//Gets name from user
cout << "Please enter your full name: ";
getline(cin, name);
//gets property value from user
cout << "Enter the actual value of the property: ";
cin >> propValue;
//Gets tax rate
cout << "Enter the tax rate for each $100 of assessed value: ";
cin >> taxRate;
cout << endl << endl;
//Calculates assessment
assessment = propValue * SIXTYPERCENT;
//Calculates Sr. Assessment
srAssessment = assessment - EXEMPT;
//Calculates annual property tax
annualPropTax = srAssessment * taxRate * TAXPERHUNDRED;
//Calculates Quarterly tax
quarterlyTax = annualPropTax / QUARTER;
//Displays owners name
cout << "Property owner's name: " << name << endl;
cout << endl;
cout << setprecision(2) << fixed;
//Displays Assesment
cout << "Assessment: " << setw(18) << "$ " << srAssessment << endl;
//Displays Annual Property tax
cout << "Annual Property Tax" << setw(11) << "$ " << std::right << annualPropTax << endl;
//Displays Quarterly Property tax
cout << "Quarterly Property Tax" << setw(8) << "$ " << std::left << quarterlyTax;
cout << endl << endl;
}
This is the current output:
Assessment: $ 175000.00
Annual Property Tax $ 7177.50
Quarterly Property Tax $ 1780.63
What I need it to do is display as so:
Assessment: $ 175000.00
Annual Property Tax $ 7177.50
Quarterly Property Tax $ 1780.63
I guess it should be intutive. Add setw to second print also:
cout << "Assessment: " << setw(18) << "$ " << setw(10) << std::right << srAssessment << endl;
// ^^^^^^^^^^^^^^^^^^^^^^^^^
cout << "Annual Property Tax" << setw(11) << "$ " << setw(10) << std::right << annualPropTax << endl;
// ^^^^^^^^^^^
cout << "Quarterly Property Tax" << setw(8) << "$ " << setw(10) << std::right << quarterlyTax;
// ^^^^^^^^^^^^^^^^^^^^^^^^^
Add right in your cout statement
Here is another stack overflow post related:
Right Justifying output stream in C++
std::cout << std::right << std::setw(x) << "output";
Where x is an integer to represent the width of the following "output".
Related
I'm writing this code for my programming class and I got everything else to work however my output formatting isn't working out for me.
#include <iostream>
#include <iomanip>
#include <ios>
using namespace std;
int main()
{
double tip_fifteen;
double tip_twenty;
double tax;
double bill;
char dollars = '$';
float meal_cost;
cout << "Enter the meal cost: ";
cin >> meal_cost;
tip_twenty = meal_cost * .20;
tip_fifteen = meal_cost * .15;
tax = meal_cost * 0.0975;
cout << "******************************************" << endl;
//beginning outputs
int digits;
digits = meal_cost * 100 / 100;
cout << setw(10) << left << "Meal Cost " << dollars;
cout << setw(to_string(digits).length() + 3) << fixed << showpoint << setprecision(2) << meal_cost << endl;
cout << setw(10) << left << "Tax " << dollars;
cout << setw(to_string(digits).length() + 3) << fixed << showpoint << setprecision(2) << tax << endl;
cout << setw(10) << left << "Tip (15%) " << dollars;
cout << setw(to_string(digits).length() + 3) << fixed << showpoint << setprecision(2) << tip_fifteen << endl;
//tip outputs then final output statements
cout << setw(10) << left << fixed << setprecision(2) << "Tip (20%) " << dollars << tip_twenty << endl;
bill = tip_fifteen + meal_cost + tax;
cout << "Your total bill is " << fixed << setprecision(2) << dollars << bill << " after 15% gratuity." << endl << "or" << endl;
bill = tip_twenty + meal_cost + tax;
cout << "Your total bill is " << fixed << setprecision(2) << dollars << bill << " after 20% gratuity." << endl;
return 0;
I want my output to look like this
Enter the meal cost: 56
******************************************
Meal Cost $ 56.00
Tax $ 5.46
Tip (15%) $ 8.40
Tip (20%) $ 11.20
Your total bill is 69.86 after 15% gratuity.
or
Your total bill is 72.66 after 20% gratuity.
my output looks like this
Enter the meal cost: 56
******************************************
Meal Cost $56.00
Tax $5.46
Tip (15%) $8.40
Tip (20%) $11.20
Your total bill is $69.86 after 15% gratuity.
or
Your total bill is $72.66 after 20% gratuity.
I'm having a problem using setw with floats however it's not working when i try to set the same variable as an int.
I've also tried using setw(25) to see if that would work somehow unfortunately it has not
You need to use right if you want them aligned to the right, you also need to add a space " " after the dollars
cout << setw(10) << left << "Meal Cost " << dollars << " ";
cout << setw(to_string(digits).length() + 3) << fixed << right << showpoint << setprecision(2) << meal_cost << endl;
To this to all of the printed statements and you will get:
******************************************
Meal Cost $ 56.00
Tax $ 5.46
Tip (15%) $ 8.40
Tip (20%) $ 11.20
For there to be padding in the price column, setw has to be set to a large enough width.
For example:
std::cout << "$" << std::setw(10) << std::fixed
<< std::setprecision(2) << 56.0f << std::endl;
Prints:
$ 56.00
Your code sets the width to:
std::to_string(digits).length() + 3
Which is only 5 characters, just enough to fit "56.00". For additional padding on the left you should increase the setw width.
My objective is to calculate and output a loan repayment schedule. The thing I would like to get help on is putting the principles added to the equation and printing out the repayment schedule. I am not sure if I did the calculations right as I have not had a personal finance class yet, and still get to grasp the concept of loans.
The loan repayment schedule is based on full price of an auto, their interest rate and their payment, assuming no money is put down. All fees and taxes are included in the price and will be financed. I also have to out put the repayment schedule to both the screen and a file - one month per line. . If the user has a credit rate of 800, they get a 3% annual interest rate; 700+ gets 5% interest rate; 600+ get 7% interest rate; and less than 600 get 12% interest rate
The credit scores for 700, 600, and below 600 are left blank because I am just going to copy the 800 credit score part again but change the interest rates.
// This program calculates a loan depending on the pereson's credit score
// how much they can pay per month. It almost outputs the month, principal,
// payment, interest, and the money that's been applied
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
int main() {
int month = 0, creditScore = 0, whichCar;
double principle, payment = 0.0, interestPaid, applied, interestRate;
cout << fixed << setprecision(2) << showpoint; // Sets total or whatever to 2 decimal points
cout << "---------------------------------------------" << endl; // Displays welcome banner
cout << "| |" << endl;
cout << "| JOLLY GOOD SHOW WE HAVE CARS AYEEE |" << endl;
cout << "| |" << endl;
cout << "---------------------------------------------" << endl;
cout << endl;
cout << "Hey, I see you want a car. You can only purchase one car though." << endl;
cout << endl;
cout << "1. Furawree: $6,969.69" << endl; // Displays menu of autos
cout << "2. Buggee: $420,420.420" << endl;
cout << "3. Sedon: $900" << endl;
cout << "4. Truck: $900,000.90" << endl;
cout << "5. Couppee: $22,222.22" << endl;
cout << endl;
cout << "Which car would you like to purchase?" << endl; // Asks user car type and user inputs car #
cout << "Please enter the number of the car: ";
cin >> whichCar;
cout << endl;
switch(whichCar) { // If user choses a number 1-5, then it asks them how much they can pay each month for the car and their credit score
case 1: // FURAWREE
principle = 6969.69;
break;
case 2: // BUGGEE
principle = 420420.42;
break;
case 3: // SEDON
principle = 900;
break;
case 4: // TRUCK
principle = 900000.90;
break;
case 5: // COUPPEE
principle = 22222.22;
break;
default: // If user doesn't pick a number from 1-5
cout << "Yea uhhmmm we don't have that sorry, go away." << endl;
}
cout << "Please enter how much you can pay each month for this Furawree: ";
cin >> payment;
cout << "Please enter your credit score: ";
cin >> creditScore;
if (creditScore >= 800) {
interestRate = .03 / 12;
do {
interestPaid = principle * interestRate;
applied = payment - interestPaid;
month++;
} while (principle < 0) ;
cout << "Month " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
cout << month << " $" << principle << " $" << payment << " " << interestPaid << " $" << applied << endl;
} else if (creditScore >= 700) {
// Will be copied from the 800 credit score
} else if (creditScore >= 600) {
// Will be copied from the 800 credit score
} else {
// Will be copied from the 800 credit score
}
cout << endl;
cout << endl;
cout << "Your payment: $" << payment << endl;
cout << "Your credit score: " << creditScore << endl;
cout << endl;
cout << endl;
system("pause");
return 0;
}
Mate, you need to fix code under credit - 800.
loop condition is incorrect
cout is after the loop, therefore it will print only once .
principle is not incremented nor decremented . and you are checking if principle is less than 0, however principle is set more than 0. so the loop will execute only once.
you need a fix some thing like this. I have just fine tuned little bit. pls fix the rest
if (creditScore >= 800) {
interestRate = .03 / 12;
cout << "Month " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
cout <<"-------------------------------------------------------" << endl;
do {
interestPaid = principle * interestRate;
applied = payment - interestPaid;
principle = principle - applied;
cout << month << " $" << principle << " $" << payment << " " << interestPaid << " $" << applied << endl;
month++;
} while (principle > 0) ;
} else if (creditScore >= 700) {
Note :-
The above code is not following any object oriented concepts. Its not even functional programming. Introduce classes, methods to reduce headache and it will help to debug.
use \t\t to get spaces instead of spaces.
This code will need a big re-work to make it look professional .
I'm currently learning C++ and got my code to do everything I want it to but it seems as if the code is not very efficient because I basically doubled the code from my output console so it shows up in a text file. If you can, could you explain what I am doing wrong and what would you suggest I do in order to make the code more efficient. (Also column one needs to be left justify and column two has to be right justify in both console and text file which I believe I did correctly.)
/* Description: This program calculates and prints the monthly paycheck for an employee (Output in command prompt and .txt file).*/
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
char name[256];
double gross;
double fiTax;
double sTax;
double ssTax;
double mediTax;
double pPlan;
double hInsurance;
double tax;
double total;
int main() {
std::cout << "Please enter your name: ";
std::cin.getline(name, 256);
cout << "Please enter your gross amount: ";
cin >> gross;
std::cout << std::fixed;
std::cout << std::setprecision(2);
fiTax = gross * .15;
sTax = gross * .035;
ssTax = gross * .0575;
mediTax = gross * .0275;
pPlan = gross * .05;
hInsurance = 75;
tax = fiTax + sTax + ssTax + mediTax + pPlan + hInsurance;
total = gross - tax;
system("cls");
ofstream file;
file << std::fixed << std::setprecision(2);
file.open("report.txt");
cout << left<< setw(28) << name << endl;
file << left << setw(28) << name << endl;
cout << left << setw(28) << "Gross Amount: ............ $";
cout << right << setw(7) << gross << endl;
file << left << setw(28) << "Gross Amount: ............ $";
file << right << setw(7) << gross << endl;
cout << left << setw(28) << "Federal Tax: ............. $";
cout << right << setw(7) << fiTax << endl;
file << left << setw(28) << "Federal Tax: ............. $";
file << right << setw(7) << fiTax << endl;
cout << left << setw(28) << "State Tax: ............... $";
cout << right << setw(7) << sTax << endl;
file << left << setw(28) << "State Tax: ............... $";
file << right << setw(7) << sTax << endl;
cout << left << setw(28) << "Social Security Tax: ..... $";
cout << right << setw(7) << ssTax << endl;
file << left << setw(28) << "Social Security Tax: ..... $";
file << right << setw(7) << ssTax << endl;
cout << left << setw(28) << "Medicare/medicaid Tax: ... $";
cout << right << setw(7) << mediTax << endl;
file << left << setw(28) << "Medicare/medicaid Tax: ... $";
file << right << setw(7) << mediTax << endl;
cout << left << setw(28) << "Pension Plan: ............ $";
cout << right << setw(7) << pPlan << endl;
file << left << setw(28) << "Pension Plan: ............ $";
file << right << setw(7) << pPlan << endl;
cout << left << setw(28) << "Health Insurance: ........ $";
cout << right << setw(7) << hInsurance << endl;
file << left << setw(28) << "Health Insurance: ........ $";
file << right << setw(7) << hInsurance << endl;
cout << left << setw(28) << "Net Pay: ................. $";
cout << right << setw(7) << total << endl;
file << left << setw(28) << "Net Pay: ................. $";
file << right << setw(7) << total << endl;
file.close();
return 0;
}
Your suspicions of inefficiency are completely unwarranted and irrelevant. Such a trivial, I/O bound code has absolutely no need for optimization, and if you write the whole I/O subsystem from scratch, any performance gain will be negligible and meaningless.
You don't have a target efficiency metric, or any efficiency measurements. In other words, you neither know how fast (or slow) your code is, nor how fast it should be. Without measurements and targets, all optimization is useless (or at best, very wasteful.)
Your code could look better. Whether the extra empty lines was your work or a side-effect of pasting the code here, you just never bothered to remove them. You should keep in mind that the appearance of your code matters. (Update: I see that you've fixed this. Kudos!)
Please don't use global variables, unless you have some experience and you judge that you do need them. In this case, you don't. If you changed you variables' scopes to local, remember to initialize them as well.
Don't use char arrays to represent strings. Use std::strings. They have all the array functionality and much more, and are much safer and much more convenient.
One way to save yourself some typing/copy+pasting and eliminate some redundancy in your code (which is very bad) is to use the parent class of both the std::cout object's type and the std::ofstream type which is std::ostream. You can write functions that take an object of this type as a parameter and only once write out what you want to write out, then you will call these functions twice: once with std::cout and once with your file.
All these points aside, I hope you'll remember this: don't worry about performance and optimization unless you can objectively prove that it's a problem.
(Sorry about the tone of this response; the OP said he is a beginner and that put me in a lecturing mood!)
Update: You can write a function like this:
void LineOut (std::ostream & os, std::string const & entry, double value)
{
int dots = 28 - 2 - int(entry.size()); // 2 for ": "
if (dots < 0) dots = 0;
os << entry << ": " << std::string('.', dots) << "$" << value << std::endl;
}
// Call it like this:
LineOut(std::cout, "Gross Amount", gross);
LineOut( file, "Gross Amount", gross);
Now you'll call this function twice for each line of output: once for cout and once for your file.
There are obviously other ways, and better ways, but I doubt that they are worth it for this small a project.
You could write a function which will print the values in file and output.
void WriteToFileAndOutput(const double &val, const string &s, ofstream &fname) {
cout << left << setw(28) << s;
cout << right << setw(7) << val << endl;
fname << left << setw(28) << s;
fname << right << setw(7) << val << endl;
}
//You can use it as
WriteToFileAndOutput(gross, "Gross Amount: ............ $", file);
WriteToFileAndOutput(fiTax, "Federal Tax: ............. $", file);
C++ has built-in string datatype, use it instead of char arrays.
If you have included using namespace std then you don't have to specify again that cout, cin etc are from std namespace.
Do not use global variables.
Just for example:
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
void WriteToFileAndOutput(const double &val, const string &s, ofstream &fname) {
cout << left << setw(28) << s;
cout << right << setw(7) << val << endl;
fname << left << setw(28) << s;
fname << right << setw(7) << val << endl;
}
int main() {
string name;
double gross, fiTax, sTax, ssTax, mediTax, pPlan, hInsurance, tax, total;
cout << "Please enter your name: ";
getline(cin,name);
cout << "Please enter your gross amount: ";
cin >> gross;
cout << fixed;
cout << setprecision(2);
fiTax = gross * .15;
sTax = gross * .035;
ssTax = gross * .0575;
mediTax = gross * .0275;
pPlan = gross * .05;
hInsurance = 75;
tax = fiTax + sTax + ssTax + mediTax + pPlan + hInsurance;
total = gross - tax;
ofstream file;
file << fixed << setprecision(2);
file.open("report.txt");
cout << left << setw(28) << name << endl;
file << left << setw(28) << name << endl;
WriteToFileAndOutput(gross, "Gross Amount: ............ $", file);
WriteToFileAndOutput(fiTax, "Federal Tax: ............. $", file);
WriteToFileAndOutput(sTax, "State Tax: ............... $", file);
WriteToFileAndOutput(ssTax, "Social Security Tax: ..... $", file);
WriteToFileAndOutput(mediTax, "Medicare/medicaid Tax: ... $", file);
WriteToFileAndOutput(pPlan, "Pension Plan: ............ $", file);
WriteToFileAndOutput(hInsurance, "Health Insurance: ........ $", file);
WriteToFileAndOutput(total, "Net Pay: ................. $", file);
file.close();
return 0;
}
One way you can reduce the redundancy in your code is to create a function to do the printing. The C++ output stream classes are all subclasses of std::ostream. This means you can write a function that accepts std::ostream& (reference to std::ostream) and pass it any output stream like std::cout or an std::ofstream.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
char name[256];
double gross;
double fiTax;
double sTax;
double ssTax;
double mediTax;
double pPlan;
double hInsurance;
double tax;
double total;
// function prints info to any std::ostream
void print_to(std::ostream& out)
{
out << left<< setw(28) << name << endl;
out << left << setw(28) << "Gross Amount: ............ $";
out << right << setw(7) << gross << endl;
out << left << setw(28) << "Federal Tax: ............. $";
out << right << setw(7) << fiTax << endl;
out << left << setw(28) << "State Tax: ............... $";
out << right << setw(7) << sTax << endl;
out << left << setw(28) << "Social Security Tax: ..... $";
out << right << setw(7) << ssTax << endl;
out << left << setw(28) << "Medicare/medicaid Tax: ... $";
out << right << setw(7) << mediTax << endl;
out << left << setw(28) << "Pension Plan: ............ $";
out << right << setw(7) << pPlan << endl;
out << left << setw(28) << "Health Insurance: ........ $";
out << right << setw(7) << hInsurance << endl;
out << left << setw(28) << "Net Pay: ................. $";
out << right << setw(7) << total << endl;
}
int main() {
std::cout << "Please enter your name: ";
std::cin.getline(name, 256);
cout << "Please enter your gross amount: ";
cin >> gross;
std::cout << std::fixed;
std::cout << std::setprecision(2);
fiTax = gross * .15;
sTax = gross * .035;
ssTax = gross * .0575;
mediTax = gross * .0275;
pPlan = gross * .05;
hInsurance = 75;
tax = fiTax + sTax + ssTax + mediTax + pPlan + hInsurance;
total = gross - tax;
system("cls");
// an std::ofstream is a sub-class of std::ostream
ofstream file;
file << std::fixed << std::setprecision(2);
file.open("report.txt");
print_to(file);
file.close();
// an std::cout is a sub-class of std::ostream
print_to(std::cout);
return 0;
}
I'm having some issues using setprecision. I don't understand how it works completely. I searched the problem and was able to extrapolate some code that should've worked. I don't understand why it's not. Thank you for your help, I'm still kind of new at this.
//monthly paycheck.cpp
//Paycheck Calculator
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
//Constants
const double
FEDERAL_TAX = 0.15, //Federal Tax
STATE_TAX = 0.035, //State Tax
SSA_TAX = 0.085, //Social Security & Medicare
HEALTH_INSURANCE = 75; //Health Insurance
//Variables
int year;
double grossAmount;
string employeeName, month;
// Initialize variables with input
cout << "Hello, what's your first name? ";
cin >> employeeName;
cout << "What is your gross amount? ";
cin >> grossAmount;
cout << "Please enter the month and year: ";
cin >> month >> year;
// Output
cout << "***********************************" << endl;
cout << "Paycheck" << endl;
cout << "Month: " << month << "\tYear: " << year << endl;
cout << "Employee Name: " << employeeName << endl;
cout << "***********************************" << endl;
cout << setprecision(5) << fixed;
cout << "Gross Amount: $" << grossAmount << endl;
cout << "Federal Tax: $" << FEDERAL_TAX*grossAmount << endl;
cout << "State Tax: $" << STATE_TAX*grossAmount << endl;
cout << "Social Sec / Medicare: $" << SSA_TAX*grossAmount << endl;
cout << "Health Insurance: $" << HEALTH_INSURANCE << endl << endl;
cout << "Net Amount: $" << fixed << grossAmount-grossAmount*(FEDERAL_TAX+STATE_TAX+SSA_TAX)-HEALTH_INSURANCE << endl << endl;
system("PAUSE");
return 0;
}
If you want to format floats to display with 2 decimal places in C++ streams, you could easily:
float a = 5.1258f;
std::cout << std::fixed << std::setprecision(2) << a << std::endl;
See std::fixed and std::setprecision
Use stream manipulators:
std::cout.fixed;
std::cout.precision(Number_of_digits_after_the_decimal_point);
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!!!
Because state_tax_payment and total_tax_payment are not initialize state_tax_payment = net_sales / state_tax_payment; and county_tax_payment = net_sales / county_tax_payment; lines can be result in undefined behavior
Initialize the all float variables
Assign some value to state_tax_payment and total_tax_payment
Correct the type mention by ' Thomas Matthews'.
Then your program works fine . May be it exit after execution finish. so you can add something like 'getchar()' , std::cin.get() to pause the console.
The actual problem was identified by Tony D.
The debugger in Xcode had a breakpoint set to the particular line of code. I simply had to drag it out of the gutter. For those who don't know, that the green arrow on the left in of the lines of code is a breakpoint. Drag it to the bottom, out of the code, to remove it.
I'm sure I made a total newbie mistake, since I am one, but lesson learned.