swolll 32 Light Poster

This is seg faulting whenever I try to remove anything. I've been trying to fix it for hours, to no avail.

Any ideas?

#ifndef BST_H_
#define BST_H_

#include <stdexcept>
#include <iostream>
#include "btnode.h"

using namespace std;

/*
	A class to represent a templated binary search tree.
*/
template <typename T>
class BST
{
	private:
	
		//pointer to the root node in the tree
		BTNode<T>* root;
		
	public:
		
		//default constructor to make an empty tree
		BST();
		
		/*
			You have to document these 4 functions
		*/
		void insert(T value);
		bool search(const T& value) const;
		bool search(BTNode<T>* node, const T& value) const;
		void printInOrder() const;
		void remove(const T& value);
		
		//function to print out a visual representation
		//of the tree (not just print the tree's values 
		//on a single line)
		void print() const;
		
	private:
		
		//recursive helper function for "print()"
		void print(BTNode<T>* node,int depth) const;
};

/*
	Default constructor to make an empty tree
*/
template <typename T>
BST<T>::BST()
{
	root = NULL;
}

template <typename T>
void BST<T>::insert(T value)
{
	BTNode<T>* newNode = new BTNode<T>(value);
	cout << newNode->data;
	if(root == NULL)
	{
		root = newNode;
		return;
	}
	BTNode<T>* current = root;
	while(true)
	{
		if(current->left == NULL && current->right == NULL)
			break;
		if(current->right != NULL && current->left != NULL)
		{
			if(newNode->data > current->data) 
				current = current->right;
			else if(newNode->data < current->data)
				current = current->left;
		}
		else if(current->right != NULL && current->left == NULL)
		{
			if(newNode->data < current->data) 
				break;
			else if(newNode->data > current->data)
				current = current->right;
		}
		else if(current->right == NULL && current->left != NULL)
		{
			if(newNode->data …
swolll 32 Light Poster

Urgent bump is urgent. I have an hour right now to sort this out. Any help would be much appreciated.

Narue commented: It's not urgent for us, and bumping is rude to everyone else who has a question. -4
swolll 32 Light Poster

I've used a debugger, and the seg faults occur whenever I use a statement with allPlaylists/listSongs.

For example, like this: allPlaylists.at(0).listSongs.at(0)->getSongName();

How can I use Songs getSongName function for listSongs (which is of type *Songs)?

swolll 32 Light Poster

You say that listongs is a vector of song* so the proper way to access its members is with a ->
so something like: cout << allPlaylists.at(0).listSongs.at(0)->getSongName(); might work

No dice. I've tried all variations of that statements. I think I'm accessing the songs wrong. Do I need a return songName function in Playlist as well as Song.

swolll 32 Light Poster

I post on the others. They take a few hours to respond usually.

Song.H

#ifndef SONGS_H_
#define SONGS_H_

#include <string>
#include <vector>
using namespace std;

class Songs																				// Songs - Class of song information and functions.
{
	private:
		string songName;																// songName = Name of song.
		string artistName;																// artistName = Name of artist.
		string albumName;																// albumnName = Name of album.
		string genre;																	// genre = Genre of song (5 options).
        int playTime; 																	// playTime = Song length in positive seconds.
        int year;																		// year = Year song was made (positive integer; >= 1900).
		int starRating;																	// starRating = Song star rating given by user (1-5).
	public:
		Songs();																		// Default Constructor - Sets everything to "nothing".
		Songs(string SN, string ArN, string AlN, int PT, int YR, int SR, string GR);	// Constructor - Sets everything to user input.
		string getSongName();															// Getter - Gets song name.
		void setSongName(string newSong);												// Setter - Sets song name.
		string getArtistName();															// Getter - Gets artist name.
		void setArtistName(string newArtist);											// Setter - Sets artist name.
		string getAlbumName();															// Getter - Gets album name.
		void setAlbumName(string newAlbum);												// Setter - Sets album name.
		int getPlayTime();																// Getter - Gets play time.
		void setPlayTime(int newTime);													// Setter - Sets play time.
		int getYear();																	// Getter - Gets song year.
		void setYear(int newYear);														// Setter - Sets song year.
		int getStarRating();															// Getter - Gets star rating.
		void setStarRating(int newStarRating);											// Setter - Sets star rating.
		string getSongGenre();															// Getter - Gets song …
swolll 32 Light Poster

I think the problem is how I access the second vector, but I don't know how to fix it.

cout << allPlaylists.at(0).getPlaylistName(); // Does work, but...

cout << allPlaylists.at(0).listSongs.at(0).getSongName(); // Causes a seg fault.

How would I access a function for a vector of a vector if not that way?

swolll 32 Light Poster

allPlaylists is a vector of type Playlist.

listSongs is a vector of type *Songs.

//Loop that goes through each element in the playlist vector.
				for(int k = 0; k < allPlaylists.size(); k++)
				{		
                                        // loop that goes through each song within the Playlist vector element. listSongs is a vector of Song pointers.
					for (int g = 0; g < (allPlaylists.at(k).listSongs.size() - 1); g++)								
					{ 
                     // Checks if songDelete (input earlier) is an element in any of the playlists.
                     // If it is, checks if artistDelete is an element of that of the playlist for that song.
						if(songDelete == allPlaylists.at(k).listSongs.at(g)->getSongName())
							if(artistDelete == allPlaylists.at(k).listSongs.at(g).getArtistName())
							{
	// If the song and artist exist, I delete that song element from the vector listSongs, and output a message.							allPlaylists.at(k).listSongs.erase(allPlaylists.at(k).listSongs.begin() + g);
								cout << songDelete << "was deleted from your " << allPlaylists.at(k).getPlaylistName() << " playlist." << endl;
								continue;
							}
					}
                  // Then I delete the element from the entire music library. library is a vector of Song objects.
				cout << songDelete << " was deleted from the library." << endl; 
				break;
				}

No matter what I do, I get a Seg Fault. I think I need to erase the Playlist pointers to the songs before I can erase the song object in library, right?

swolll 32 Light Poster

Okay. So Eclipse is a no? My teacher actually recommended it over those two.

swolll 32 Light Poster

Until now, I've coded in Notepad++ and compiled/tested in my university Unix account.

This is getting tedious and inefficient, though. So, what can I do about it?

Notepad++ doesn't have a compiler or debugger. I was thinking about using Eclipse. Would that be a good, free option? Does it have a compiler and debugger?

What do you recommend?

swolll 32 Light Poster

I've worked on it for a few days. It works great when I comment out the erase function. But it doesn't work when I include the erase function, which I use to remove an element in the playlist vector of type Songs.

Here's the else if statement. The problem is the "playlist.erase(j);". I've done it in everyway possible (ie - playlist.at(j).erase(); and many other variations)

else if(deleteChoice == 'd')
		{
			cin.ignore(10,'\n');
			cout << "Please enter the exact song name you would like to delete: ";
			getline(cin, songDelete);
			for (int j = 0; j < playlist.size(); j++)
			{
				if(songDelete == playlist.at(j).getSongName())
				{
					playlist.erase(j);
					cout << "The song has been deleted." << endl;
					flag = false;
					break;
				}
			}
			if(flag == true)
			{
				cout << "Song not found. Please try again." << endl;
				continue;
			}
		}

Here's the full function if that helps:

void Songs::addSongLibrary(vector<Songs> &library, vector<Songs> &playlist)
{
	char choosePlaylist;
	cin.ignore(10000,'\n');
	cout << "Please enter song name: ";
	getline(cin, songName);
	cout << "Please enter artist name: ";
	getline(cin, artistName);
	cout << "Please enter album name: ";
	getline(cin, albumName);
	cout << "Please enter length of song in seconds: ";
	cin >> playTime;
	while(true)
	{
		if(!cin.fail() && playTime > 0)
			break;
		else if(cin.fail())
		{
			cout << "Time must be in seconds. ";
			cin.clear();
			cin.ignore(1000,'\n');
		}
		else if(playTime < 0)
		{
			cout << "Seconds cannot be negative. ";
			cin.clear();
			cin.ignore(1000,'\n');
		}
		cout << "Please enter length of song in seconds: ";
		cin >> playTime;		
	}
	cout << "Please enter …
swolll 32 Light Poster

Hey guys.

I need to write a program that does the following:
Requirements - The program...
- Shall allow user to enter individual songs with information:
- Shall ask for song name.
- Shall ask for length.
- Shall ask for artist name.
- Shall ask for album name.
- Shall ask for music genre.
- Shall ask for personal star rating.
- Shall ask for song year.
- Shall validate (and if needed reask for) song data:
- Shall validate that length is in seconds and is positive.
- Shall validate that genre is selected from set of known values.
- Shall validate that personal rating is between 1 and 5.
- Shall validate that song year is 1900 or greater.
- Shall allow user to review entire library.
- Shall allow user to delete song from library (and playlist if on it).
- Shall allow user to create, edit, and review playlist:
- Shall allow user to add any song created to playlist.
- Shall allow user to review playlist.
- Shall allow user to delete song from playlist.
- Shall allow user to end program.

Here are the three files I've written so far. But can you tell me:
(a) why this header/implementation file won't compile (it says library and playlist are not right type).
(b) am I doing this the right …

swolll 32 Light Poster

I know C++, but want to be able to code web sites, web applications, and maybe iPhone apps.

I've heard that PHP and ruby on rails are good to learn. I also know there is an iPhone app language/SDK I could get my hands on.

What languages and in what order do you recommend learning? (Would one be much faster/easier to learn than another? And how?

Thanks.

swolll 32 Light Poster

Is there any specific piece of code you are looking at that is peaking your interest.. causing you to ask these questions? If so, please show us. It will help us to explain it to you if we actually have something to look at.

For the ->'s

Employee::Employee(string firstName, string lastName, int skillLevel, int benefitCode, int contribution, int hoursWorked, int id)
{
	this->firstName = firstName;
	this->lastName = lastName;
	this->skillLevel = skillLevel;
	this->benefitCode = benefitCode;
	this->contribution = contribution;
	this->hoursWorked = hoursWorked;
	this->id = id;
}

Algorithms: How would you use max_element, search, sort, and/or swap?

For the last two question, those are just general questions (no code)?

swolll 32 Light Poster

What does "->" do for vectors?

And, how do you use the vector algorithms?

And, also, when/why do you use #ifndef something_H, #define something_H, ..., #endif?

Is there a difference between "vector" and "apvector"?

swolll 32 Light Poster

1) I get this in my compiler: " company.h.gch: too short to be a PCH file
" What does it mean?

2) What does "void value..." mean.
Compiler:

companyImp.cpp: In member function 'int Company::read_list(int)':
companyImp.cpp:55: error: void value not ignored as it ought to be
companyImp.cpp:60: error: void value not ignored as it ought to be

Code from line 55:

flag = list[i].readData1(fin);
		while(flag && !fin.eof())
		{
			i++;
			if (i < size)
				flag = list[i].readData1(fin);

3) None of the following makes sense. The compiler says:

companyImp.cpp: In member function 'void Company::process_list(int)':
companyImp.cpp:75: error: 'int' is not a template
companyImp.cpp:75: error: 'size' cannot appear in a constant-expression
companyImp.cpp:75: error: expected primary-expression before 'int'
companyImp.cpp:75: error: expected `;' before 'int'
companyImp.cpp:75: error: expected primary-expression before 'int'
companyImp.cpp:75: error: expected `)' before 'int'
companyImp.cpp:75: error: declaration does not declare anything
companyImp.cpp:75: error: expected `;' before ')' token

And the code from line 71:

void Company::process_list (int size)
{

	if (size > 0)
		for (int i = 0; int < size; i++){               //line 75
			list[i].setSkillPay();
			list[i].calcGross();
			list[i].setBenefitCost();
			list[i].calcContAmountAndTotal();
			list[i].calcGrossDed();
			list[i].calcTax();
			list[i].calcNet();	
	}
}

4) Is there a way to use the length function for double type variables. For instance, I got this compiler message back:

companyImp.cpp: In member function 'void Company::searchID(int)':
companyImp.cpp:187: error: request for member 'length' in 'target', which is of non-class type 'double'
companyImp.cpp:188: error: invalid types 'double[int]' for array subscript
companyImp.cpp:188: error: invalid types 'double[int]' for array subscript

And here's the code. I'm …

swolll 32 Light Poster

Thursday bump. Any tips on composition/arrays would be welcomed, too.

swolll 32 Light Poster

Today was my first time trying composition. It's for a lab project due Friday, and I have a lot of tomorrow to work on it. However, up until we have just been using one class per program. Now, my teacher wants us to use composition and arrays, despite only lecturing on them for a few minutes. Worse, there is no section on composition (and arrays in compositions) in our notes/textbook. So, could you check this code and tell me if I'm on the right track. I don't even need help with syntactical errors (yet); I just need an idea of what I need to do, and what I'm not understanding about composition.

There are five files, and an input file. And the program (as you can see from the input file) reads the student info and stores it in an array and then outputs (1) all information in a table, (2) a student searched by last name, (3) lowest gpa student information, (4) highest units gpa information.

Thank you very much.

student.h

#ifndef student_H
#define student_H

#include <string>

using namespace std;

class Student{
	public:
		void set_Name(string, string); 	
		bool readStudent(ifstream &);
		void printStudent () const;
		Student();
		string get_Last();
		string get_First();
		void set_Major(string);
		string get_Major( );
		int get_Units();
		void set_Units(int);
		float get_GPA();
		void set_GPA(float);
	private:
		string  First, Last;
		int		Units;
		float	GPA;
		string	Major; 
};

#endif

Student Implementation

#include <iostream>
#include <fstream>
#include "student.h"

using namespace std;
void Student::set_Name(string first, string last){
	First = first;
	Last = …
swolll 32 Light Poster

It all came to to a few missing ampersands and variables, and a few misplaced calls.

Thanks so much for all of your help.

swolll 32 Light Poster

Okay. I've given you're errors a try the last few hours but am still stumped.
Specifically, it is that there are no syntax errors now, but the program doesn't work as it should. It is supposed to print employee data, but only prints zeros. Below are my code and input file, for you to see:

Code: http://pastebin.com/m897b9aa
Input: http://pastebin.com/m20f14b82

Any ideas where I go wrong?

swolll 32 Light Poster

As it turns out, my teacher gave an extension til tomorrow for a 10% point deduction.

I know the code is close to working, and it runs with syntax error, but it only outputs "bad data." I think there's a problem with the function calling/passing, but can't find/fix them for the life of me.

Any help would be tremendously appreciated.

swolll 32 Light Poster

Okay, I've tried everything that was mentioned, and I can run the program. But, it doesn't work as it should. The program is due by 12:00am and I really need help.

If you have the time, please take a look and advise.

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;

// Function Prototypes
void Program_Info (void);        
void Open_File_1(ifstream &fin);
void Output_File_1 (ofstream &fout1);
void Read_Data_1 (ifstream &fin, int skill, int benefitType, double contPercent, double hours, double taxID, string name);
double Skill_Pay (int skill);
double Gross_Pay (double skillPay, double hours);
double Benefit_Cost (int skill, int benefitType);
void Gross_Calculations (double gross, double contPercent, double &contAmount, double &contTotal, double &benefitCost, double &grossDed, int &taxRemainder);
void Taxes_and_Net (double grossDed, int taxRemainder, double &taxOwed, double &netSalary);

void Print_File_1 (ofstream &fout1, int skill, string name, double hours, int benefitType, double gross, double contPercent, double benefitCost, double contAmount, double contTotal, double taxOwed, double netSalary);
void Open_File_2(ifstream &fin1);
void Output_File_2 (ofstream &fout2);
void Read_Data_2 (ifstream &fin1, int skill, int benefitType, double contPercent, double hours, double taxID, string name);
void Print_Head_2 (ofstream &fout2);
void Print_Employee_2 (ofstream &fout2, ifstream &fin1, int skill, double hours, int benefitType, double contPercent, double taxID, string name, double skillPay, double &gross, double &benefitCost, double &contAmount, double &contTotal, double &grossDed, int &taxRemainder, double &taxOwed, double &netSalary);
void Sum_Calculations (double gross, double benefitCost, double contTotal, double taxOwed, double netSalary, double &sumGross, double &sumBenefit, double &sumContributions, double &sumTaxes, double &sumNet);
void Print_Employee_Data_2 (ofstream &fout2, ifstream &fin1, int skill, double hours, int …
swolll 32 Light Poster

This is tedious. And I'm a bit desperate. I still can't fix a numbers of errors, despite working at this since early this morning. And ideas?

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;

// Function Prototypes
void Program_Info (void);        
void Open_File_1(ifstream &fin);
void Output_File_1 (ofstream &fout1);
void Read_Data_1 (ifstream &fin, int skill, int benefitType, double contPercent, double hours, double taxID, string name);
double Skill_Pay (int skill);
double Gross_Pay (double skillPay, double hours);
double Benefit_Cost (int skill, int benefitType);
void Gross_Calculations (double gross, double contPercent, double &contAmount, double &contTotal, double &benefitCost, double &grossDed, int &taxRemainder);
void Taxes_and_Net (double grossDed, int taxRemainder, double &taxOwed, double &netSalary);

void Print_File_1 (ofstream &fout1, int skill, string name, double hours, int benefitType, double gross, double contPercent, double benefitCost, double contAmount, double contTotal, double taxOwed, double netSalary);
void Open_File_2(ifstream &fin1);
void Output_File_2 (ofstream &fout2);
void Read_Data_2 (ifstream &fin1, int skill, int benefitType, double contPercent, double hours, double taxID, string name);
void Print_Head_2 (ofstream &fout2);
void Sum_Calculations (double gross, double benefitCost, double contTotal, double taxOwed, double netSalary, double &sumGross, double &sumBenefit, double &sumContributions, double &sumTaxes, double &sumNet);
void Print_Employee_2 (ofstream &fout2, int skill, double hours, int benefitType, double contPercent, double gross, double benefitCost, double contAmount, double taxOwed, double netSalary);
void Print_Totals_2 (ofstream &fout2, double sumGross, double sumBenefit, double sumContributions, double sumTaxes, double sumNet);

int main()
{
	int skill, benefitType, taxRemainder;
	double hours, contPercent, gross, benefitCost, grossDed, contAmount, taxOwed, netSalary, contTotal, taxID, skillPay;
	double sumGross = 0, sumBenefit = 0, sumContributions = …
swolll 32 Light Poster

Thanks, dudes. I'm going to work at it for an hour or two, and post back with any questions.

A few things to start, though:
1) I'm a bit confused as to when to use/declare global variables and when to use/declare local variables. I understand their scopes, but do you usually use one for passing by value and the other for passing by reference?

2) To be clear, is it:
Function Prototype: datatype functionname (parameter list with types and identifiers of what is to be passed; include any & for references);

Function Call: functionname (parameter list with only names of identifiers; no &'s or datatype);

Function Definition: datatype functionname (paramter list with data type and name received from main; include &'s for references)

3) Can you tell if my file streams (input and output) and reading them are okay?

swolll 32 Light Poster

You can definitely skip the "upload to Linux" step. Not sure if you're a student and have a home computer and are uploading and compiling to a Linux server at school or something. You're only using the standard headers, so everything is 100% portable and thus should compile and run exactly the same in Windows and Linux, so you can just do everything on Windows. Notepad++ (which I've never used) appears not to have its own compiler, so you'd have to download and install one like mingw. http://www.mingw.org/

Or install Dev C++ or Code Blocks, both of which use mingw. Or Visual C++ from Microsoft or NetBeans. All of these have IDEs with editors, debuggers, compilers, etc. or you can continue with Notepad++ as the editor and compile from the command line. Editing and compiling are separate processes. There is also cygwin, which is sort of "Linux for Windows". Lots of options, but as I mentioned, all of your code is completely the same for both Windows and Linux.

Best advice would be to install Visual C++ or Code Blocks and use them instead of Notepad C++. You'll eventually need to use a debugger and these provide them. If you use Visual C++, always pick a "console" project, make it an empty project, and don't use the precompiled headers. It'll make the upload to Linux much less frustrating.

Okay, I have codeblocks, but have no experience with it. To debug/check my code, do I just copy and paste …

swolll 32 Light Poster

First step in debugging. Make, make your main look like this:

int main ()
{
   return 0;
}

If that gets rid of the errors, then at least your functions compile, which of course doesn't mean they are correct. If it doesn't compile, start looking at the errors. Look for any "can't find identifier" errors or "unmatched bracket" errors, "redeclaration" errors, "expected semicolon" errors, stuff like that. A single bracket or semicolon missing can cause the errors to avalanche. You should be fixing errors, then recompiling. For the most part, go from top to bottom.

You've violated the main rule of programming/debugging, which is "Don't do too much at once." You should start with working code, than change once thing at a time, compiling and fixing errors as you go. Right now you have too many, especially if this is all new to you. I'd go back to your working code without functions and sort of start over. First step: keep everything the same, but change the output code to be in functions. When that works, change the calculation code to be in functions. When that works, change the file input code to be in functions. That's three separate very broad categories, each of which are quite enough on their own to focus on. Tackling all at once is asking for trouble.

That makes sense. What do you recommend for compiling/debugging? I've been using notepad++ to edit the code and then upload to unix each time I want to check errors.

swolll 32 Light Poster

Thanks guys. I've been working on it all night. I'm a bit stumped, and was wondering:
1) Am I on the right track, and is it just small details to correct now? Or will I need to overhaul my code (and how?)?
2) My compiler gives me a bunch of syntax errors (especially primary-expression...) that I don't know how to fix. Any help would be great.

Here's the new code, and thanks so much:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;

// Function Prototypes
void Program_Info (void);        
void Open_File_1(ifstream &fin);
void Output_File_1 (ofstream &fout1);
void Read_Data_1 (ifstream &fin, int skill, int benefitType, double contPercent, double hours, double taxID, string name);
double Skill_Pay (int skill);
double Gross_Pay (double skillPay, double hours);
double Benefit_Cost (int skill, int benefitType);
void Gross_Calculations (double gross, double contPercent, double &contAmount, double &grossDed, int &taxRemainder);
void Taxes_and_Net (double grossDed, int taxRemainder, double &taxOwed, double &netSalary);
void Print_File_1 (ofstream&, int skill, string name, double hours, int benefitType, double gross, double contPercent, double benefitCost, double contAmount, double contTotal, double taxOwed, double netSalary);

void Open_File_2(ifstream &fin1);
void Output_File_1 (ofstream &fout2);
void Read_Data_2 (ifstream &fin1, int skill, int benefitType, double contPercent, double hours, double taxID, string name);
void Print_Head_2 (ofstream &fout2);
void Sum_Calculations (double gross, double benefitCost, double contTotal, double taxOwed, double netSalary, double &sumGross, double &sumBenefit, double &sumContributions, double &sumTaxes, double &sumNet);
void Print_Employee_2 (ofstream &fout2, int skill, double hours, int benefitType, double contPercent, double gross, double benefitCost, double contAmount, …
swolll 32 Light Poster

I've been working on a piece of code for a while, and it works as it is intended to. Now, though, I'm trying to the code down so that there is one main functions and every "action" is a function that is called. But, I have very little experience with functions. I have been reading up and practicing with them, but am still a little bit lost. What would you recommend doing and how would you go about breaking the code below into functions, so that it still works the same way?

Step 3 - Output:
	* Student information (name, class sections, assignment/date) 
	* Program title/mission statement
	1) Detailed individual employee reports in page format. (Stored in output file #2 and not displayed on monitor):
	Print information until all information is listed, or print "Bad Data...(reason)" after file input data is invalid.
	- Print the employee's information. 
		- Name.
		- Gross Salary.
		- Medical Benefits.
		- Retirement Contribution in percent.
			- Company contribution in dollars.
			- Employee contribution in dollars.
			- Total contributions in dollars.
		- Taxes Owed.
		- Net Salary.
		
	2) Payroll report in tabular form. (Stored in output file #1 and displayed on monitor):
	For each individual employee in the information output table.
		- Print each employee's data on one line until all information (below) is listed: 
			*Note - End output and print "Bad Data...(reason)" if file input data is invalid.
			- Name.
			- Gross Salary.
			- Benefits.
			- Contributions.
			- Taxes.
			- Net Salary.
		
	- Print …
swolll 32 Light Poster

while (!file.eof()) is a bad solution. Remember that ifstream returns 0 when it can't read desired variable from file.
Your "number" is a random number, because if your file is empty you don't write anything into it.

while (!file.eof()) is what my professor taught and expected us to use. How would you fix it, using while (!file.eof()) or something new entirely?

swolll 32 Light Poster

I need to compute the number of nonnegative numbers from an input file. Everything works fine (for good input files and bad input files) except when there is a no data file (with nothing in it). Then, the number of nonneg numbers reads 1, even though it should be 0. Any ideas on how to fix the code?

// Program SumNums reads and counts nonnegative integers until
// the end of file is reached on file SumNums.txt

#include <iostream>
#include <cctype>
#include <fstream>
#include <string>
using namespace std ;

int main ()
{
    ifstream  	data;
    int  	number;	// input value
    int  	count = 0;		// number of positive values
    string	File_Name; 	

    cout <<"Enter file name: " ;
    cin >> File_Name;
    data.open(File_Name.c_str());

	if (data.fail())			
		cout << "Bad input file." << endl << "Program stopped." << endl; 
	else
	{
		while (!data.eof())
		{
			data >> number;
			if (number >= 0)
				count = count++;
		}
    cout  << "The number of nonnegative integers is " << count  << endl;
	}
	
    return 0;
}
swolll 32 Light Poster

what compiler are you using? If it has a debugger then learn to use it so that you can find out what is wrong with your program.

I've just been using unix. Can you recommend a better one with a debugger (that is free)?

swolll 32 Light Poster

why not just post them here??

I did here. No responses. And my mistakes might be a bit complex for a forum response. http://www.daniweb.com/forums/post1008467.html#post1008467

swolll 32 Light Poster

Do any of you have aim or google talk or email that I could ask some C++ questions through?

swolll 32 Light Poster

That didn't work. Here's my code. Where did I go wrong?

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int main()
{
	int skill, benefitType, skillPay, taxRemainder;
	double hours, contPercent, gross, benefitCost, grossDed, contAmount, taxOwed, netSalary, contTotal;
	double sumGross = 0, sumBenefit = 0, sumContributions = 0, sumTaxes = 0, sumNet = 0;
	string name, taxID, benefitName;
	string fileInput1, fileInput2, fileOutput1, fileOutput2;

	ifstream fin;
	ofstream fout1, fout2; 

	cout << "Enter input file name for detailed employee reports in page format: ";	
	getline(cin, fileInput1);
	fin.open(fileInput1.c_str());
	
	if (fin.fail())			
		cout << "Bad input file." << endl << "Program stopped." << endl;
	else
	{
		cout << "Enter output file name for detailed employee reports in page format: ";	
		cin >> fileOutput1;					
		fout1.open(fileOutput1.c_str()) ;	
		
		fout1 << "Detailed Employee Reports:" << endl;

		fin >> skill >> benefitType >> contPercent >> hours;
		getline(fin, taxID);	
		getline(fin, name);

		while (!fin.eof())	
		{						
			if (skill == 1)
					skillPay = 15.00;
				else if (skill == 2)
					skillPay = 25.00;
				else if (skill == 3)
					skillPay = 72.00;
				else if (skill == 4)
					skillPay = 125.00;

		if (hours <= 40)
				gross = hours * skillPay;
			else if (hours <= 50)
				gross = (40 * skillPay) + ((hours - 40) * (skillPay * 1.5)); 
			else if (hours <= 60)
				gross = (40 * skillPay) + (10 * (skillPay * 1.5)) + ((hours - 50) * (skillPay * 2));

		if (skill = 1 || benefitType == 0)
			benefitCost = 0;			
		else if (benefitType == 1)	
			benefitCost = 32.50;
		else …
swolll 32 Light Poster

New Question. I end the output to one file (fout1) and try to start it to a new input and output file, using this code:

" fout1.close();
}

cout << endl << "Detailed employee reports have been printed in " << fileOutput1 << "." << endl << endl;
cout << "Enter input file name for company payroll report. (Can be same as first input file.): " << endl;	
getline(fin, fileInput2);
fin.open(fileInput2.c_str());

if (fin.fail())	
cout << "Bad input file." << endl << "Program stopped." << endl;
else
{
fin >> skill >> benefitType >> contPercent >> hours;
getline(fin, taxID);
getline(fin, name);

cout << "Enter output file name for company payroll report: ";	
cin >> fileOutput2;	
fout2.open(fileOutput2.c_str()) ;

cout << "Name \t \t Gross Salary \t Benefits \t Contributions \t Taxes \t Net Salary" << endl;
fout2 << "Name \t \t Gross Salary \t Benefits \t Contributions \t Taxes \t Net Salary" << endl;

while (!fin.eof())	"

But, when compiled, nothing shows up after the first output stream finishes. Where did I go wrong?

swolll 32 Light Poster

pow (23, 2)
You're passing two integers.

> 'pow(int, int)' is ambiguous
two integers is confusing....

> double std::pow(double, int)
A variety of combinations involving floating point types is offered.

Pick one, and make an appropriate constant a float (of whatever type).

Thanks so much.

swolll 32 Light Poster

Taking a stab at guessing line 98

VoltageGain = double pow ((275 / sqrt (pow (23, 2) + 0.5 * pow (f, 2))), n);

What does double do here?

I'm not sure. But, if I leave it out, I get this:

g++ assignment2.cpp
assignment2.cpp: In function 'int main()':
assignment2.cpp:98: error: call of overloaded 'pow(int, int)' is ambiguous
/usr/include/iso/math_iso.h:63: note: candidates are: double pow(double, double)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:373: note:                 long double std::pow(long double, int)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:369: note:                 float std::pow(float, int)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:365: note:                 double std::pow(double, int)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:361: note:                 long double std::pow(long double, long double)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:357: note:                 float std::pow(float, float)
swolll 32 Light Poster

Here is my code:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const double e = 2.71828;
double t, f, n, B, VoltageGain;

cout << "Please enter the time in hours the culture has been refrigerated:        ";
cin >> t;
cout << endl;

while (t < 0)
{
  cout << "t cannot be a negative value." << endl << endl;
  cout << "Please enter the time in hours the culture has been refrigerated:        ";
  cin >> t;
}
 	B = 300,000 * pow(e, -0.032 * t);
	
cout << fixed << showpoint;	
cout << "The number of bacteria in the culture after " << setprecision(6) << t << " hours of refrigeration is " << setprecision(6) << B << endl;

cout << "Please enter the amplifier's frequency in Hertz:        "; 
cin >> f;
cout << endl;

while (f < 0)
{
  cout << "f cannot be a negative value." << endl << endl;
  cout << "Please enter the amplifier's frequency in Hertz:        ";
  cin >> f;
}
	
cout << "Please enter the number of stages in the amplifier:        "; 
cin >> n;
cout << endl;

while (n < 0)
{
  cout << "n cannot be a negative value." << endl << endl;
  cout << "Please enter the number of stages in the amplifier:        ";
  cin >> n;
}
	VoltageGain = double pow ((275 / sqrt (pow (23, 2) + 0.5 * pow (f, 2))), n);

cout << fixed << showpoint;	
cout << "The voltage …
Salem commented: congrats on using code tags on your first post +36