NathanOliver 429 Veteran Poster Featured Poster

Another apporach would be to use getline. Something like this should work

string filename;
cout << "Enter the filename: ";
getline(cin, filename);
ifstream OpenFile(filename.c_str());
//...

You will need to add #include<string> to your code for this to work. Also you are using the headers you have are depreacted. You have

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

// change that to this
#include <iostream>
#include <fstream>

BTW what compiler are you using?

Aranarth commented: Appropriate solution for the problem +1
NathanOliver 429 Veteran Poster Featured Poster

why do you have median in your main paramaters? medain should be defined in main

int main()
{
    float meadian = 0;
    // rest of your code
}
cloudulous commented: great help +0
NathanOliver 429 Veteran Poster Featured Poster

you are not actualy defining string B. to define it to be be you could do this

string B = "B";
NathanOliver 429 Veteran Poster Featured Poster

This is a link to Narue's sticky on posting questions
http://www.daniweb.com/forums/thread78223.html

As far as I'm concerned this should be read by everyone who joins before the start posting.

jonsca commented: Yes. If only everyone could read simple instructions. +4
NathanOliver 429 Veteran Poster Featured Poster

I am sad that he will not be with us anymore. He had given me some wonderful advice and wasn't afraid to call me out if what I said was incorrect. He will be missed

NathanOliver 429 Veteran Poster Featured Poster

well I'm not seeing a getName() function that returns an int so I'm clueless.

NathanOliver 429 Veteran Poster Featured Poster

Hey all

I have seen a lot of stuff about palindrome checkers so I thought I would write one that works for STL containers as well as arrays. it accepts a bidirectional iterator to the first element and an bidirectional iterator to 1 after the last element. Included is a sample of it working with a string and a vector of int's. At most this function requires O N/2 iterations(correct me please if I'm wrong). Also I chose for single characters to be considered a palindrome. I hope you guys will find this useful.

NathanOliver 429 Veteran Poster Featured Poster

it could be that y1 is declared in the <cmath> header and since you declared them as global you are getting the error. what happens if you do this instead instead of having a main.h. I mean put all this in main.cpp

#include <iostream>
#include <cmath>

/* Namescapes */
using namespace std;

int main() {
        /* Varibles */
        double x1;
        double x2;
        double y1;
        double y2;
        double answer;
	/* Title */
	cout << "Fellixombc's Distance Formula Application (Geometry)\n" << "x1: ";
	
	/* Application Input/Output */
	cin >> x1;
	cout << "x2: ";
	cin >> x2;
	cout << "y1: ";
	cin >> y1;
	cout << "y2: ";
	cin >> y2;
	
	/* Calculations */
	answer = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	
	cout << answer;
	
	system("pause");
	
}

And yes those are common names. you should use real names for your variables.

NathanOliver 429 Veteran Poster Featured Poster

the reason is that when you declare a variable it is given a memory address and what ever happens to be in that address is what the variable is now equal to. so when you do int i; i has the value of whatever the memory its using has. so to avoid problems you normally want to set them to 0 before you and an manipulations with them.

int i;
i += 100;
cout << i;  // i could be whaterever

// safe approach
int i = 0;
i += 100;
cout << i;  // 100

If you are going to assign to a variable before manipulating it then it is fine to declare it without initializing it.

int i;
i = 100;
i += 1;
cout << i;  // 101

you just don't want to use a variable before you put something in it or as Sodabread said it will have crap in it and nobody wants to have crap.

jonsca commented: Good +4
NathanOliver 429 Veteran Poster Featured Poster

alright I looked into it and i forgot to add a least case scenario since my algorithm for making the sets always found the largest set to make the permutations. Now I'm running my minimum value to 2 since i already have 1 covered in the largest first set. my machine is a little old running and only has a 500 MHz processor with 640 MB ram so my total time was 120 ms with L = 7 and M = 3. I also fixed another error in my code. I forgot to have a return if the set was evenly divisible by M.
my output was

[[0,1,2,3,4], [5], [6]]
[[0], [1,2,3,4,5], [6]]
[[0], [1], [2,3,4,5,6]]
[[0,1,2,3], [4,5], [6]]
[[0,1], [2,3,4,5], [6]]
[[0,1,2,3], [4], [5,6]]
[[0], [1,2,3,4], [5,6]]
[[0,1], [2], [3,4,5,6]]
[[0], [1,2], [3,4,5,6]]
[[0,1,2], [3,4,5], [6]]
[[0,1,2], [3], [4,5,6]]
[[0], [1,2,3], [4,5,6]]
[[0,1], [2,3], [4,5,6]]
[[0,1], [2,3,4], [5,6]]
[[0,1,2], [3,4], [5,6]]
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <sys/types.h>
#include <sys/timeb.h>


using namespace std;

vector< vector< vector<int> > > MakeSubsets(vector<int>, vector< vector<int> >, int);

vector< vector<int> > CalculatePossibleSets(int, int, int, int);

vector<int> CalculatePossibleSetSizes(int, int, int);

void Print(vector< vector< vector<int> > >);

int main()
{
	_timeb start, end;
	unsigned int milliseconds, setSize, numberOfSets, maxSubSetSize, minimumSubSetSize;
	cout << "This program will find all possible subsets of consecutive numbers";
	cout <<	"\nfor a given number of sets and a given range of numbers.";
	cout << "\nPlease enter how large you want the set to be: ";
	cin …
NathanOliver 429 Veteran Poster Featured Poster

Well to start things off i have be going a little STL crazy lately. I'm having fun playing around with all the things you can do so I decided to give this an entire STL approach. There is probably a faster way but this was fun and some good practice. I hope you guys enjoy this one.

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <sys/types.h>
#include <sys/timeb.h>


using namespace std;

vector< vector< vector<int> > > MakeSubsets(vector<int>, vector< vector<int> >, int);

vector< vector<int> > CalculatePossibleSets(int, int, int, int);

vector<int> CalculatePossibleSetSizes(int, int, int);

void Print(vector< vector< vector<int> > >);

int main()
{
	_timeb start, end;
	unsigned int milliseconds, setSize, numberOfSets, maxSubSetSize, minimumSubSetSize;
	cout << "This program will find all possible subsets of consecutive numbers";
	cout <<	"\nfor a given number of sets and a given range of numbers.";
	cout << "\nPlease enter how large you want the set to be: ";
	cin >> setSize;
	cout << "Please enter the number of subsets: ";
	cin >> numberOfSets;
	cin.get();
	_ftime(&start);
	maxSubSetSize = setSize - numberOfSets + 1;
	if (setSize % numberOfSets == 0)
		minimumSubSetSize = setSize / numberOfSets;
	else
		minimumSubSetSize = (setSize / numberOfSets) + 1;
	vector<int> numberSet;
	for (int i = 0; i < setSize; i++)
		numberSet.push_back(i);
	vector< vector<int> > permutations;
	vector< vector< vector<int> > > allSubSets;
	permutations = CalculatePossibleSets(setSize, maxSubSetSize, numberOfSets, minimumSubSetSize);
	allSubSets = MakeSubsets(numberSet, permutations, numberOfSets);
	Print(allSubSets);
	_ftime(&end);
	milliseconds = (end.time * 1000 + end.millitm) - (start.time * 1000 + start.millitm);
	cout << "\nToltal time was " << …
NathanOliver 429 Veteran Poster Featured Poster

>>Hi I M Rameshwar Prasad Sahu From Bilaspur, Chhattisgarh, I M working as computer faculty and Here the solution of your question Libraby Management System. If You have any problem with this coding Email me your problem at: <<EMAIL SNIPPED>>

My god how is this possible. I mean come on. If you are going to just give him the code you might as well just give him a job since you will be doing his work anyway. PLEASE refrain from just handing out answers.

jonsca commented: Yup +4
NathanOliver 429 Veteran Poster Featured Poster

for virtual functions http://www.codersource.net/c/c-tutorials/c-virtual-function.aspx

as for splitting the files the .h function should have the deceleration of the class and the .cpp should have the definitions of all the class function. something like this

//foo.h

class Foo
{
public:
       Foo();
       ~Foo() {}
private:
       int bar;
};

// foo.cpp
Foo::Foo()
{
       bar = 0;
}
NathanOliver 429 Veteran Poster Featured Poster

code you post your class code. its hard to see your screen from here ;)

NathanOliver 429 Veteran Poster Featured Poster

first for your strncmp you need to make pass the string email_address as a char*. to do this you need to use the c_str() method

strncpy(userId, email_address.c_str(), 9);

second isalpha actually takes an int so you can only use a single character not a whole string so you would need to write a for loop to go through each element of the array and call isalpha on that.

third you are using do..while loops. i would use while loops instead because as it stands you will run the loop at lease once even if your input is correct. also i believe you are calling functions in you while part of the loop but there is no (). if

}while(user_ID_length==false);

// did you mean?

}while(user_ID_length(userId, length) == false);

if you have any more problems please post them and i would be happy to help

The ICE Man commented: Good Points, well done :) +0
jonsca commented: Agreed +4
NathanOliver 429 Veteran Poster Featured Poster

You are mixing input types. After your call to cin >> tmp you need to clear the input buffer. You can use cin.ignore() for this. If that does not work narue has a good sticky thread on how to clear the input buffer that is very informative

NathanOliver 429 Veteran Poster Featured Poster

Please refrain from name calling. Salem is a great poster and has some very good advice. you did not post any code or say what this is for so even i though it was asking for homework help. it is best to clearly state what is going on becuase we have no information to go on besides what you have posted.

with that siad i would suggest 2 loops. since you could have multiple's of the same number as a factor. the first loop would run through each digit and the second loop would divide the number as many times as it can by that number. a for loop and a while loop would probably work great.

a good example is the number 8. its factors are 2-2-2 but with your code as above you would get 2-4 which is not correct. my approach would test 2 multiply times and give as an output 2-2-2.

NathanOliver 429 Veteran Poster Featured Poster

What Fbody said. The variables were already declared in the function declaration so when you re defined them the became garbage and were giving you a incorrect answer. Also your formula for calculating the average is flawed.

NathanOliver 429 Veteran Poster Featured Poster

Look at line 70. Notice anything particular about it? Also line 98 is wrong. Your instructions say to calculate the average of the 3 highest scores to the nearest integer. Does a double qualify as an integer? These are some things for you to look at. Remember it is better to start small and debug constantly then to write the whole program and hope it works.

NathanOliver 429 Veteran Poster Featured Poster

you would need to reset i to zero and then assign the return to s2 and increment i after each time.

NathanOliver 429 Veteran Poster Featured Poster

the function collision you have for your coord class right now is collision(coord[]). im saying just to make it collision(coord). then in the function re write your if statement to look like

if(this->xx == asteroid.getxx() && this->yy == asteroid.getyy())
NathanOliver 429 Veteran Poster Featured Poster

the problem is when you pass an array to a function the actual thing that gets passed is a pointer to the first element of the array. the function doesn't know its an array so it doesn't know that he address after the pointer are part of the array. there are to ways to go about this dilemma. first you could pass the size of the array to the function so it knows hat the upper bound is.

int size = 0;
cout << "please enter the number of employees you want to enter: ";
cin >> size;
char * employees = new char[size]; // create a dynamic array
sort(employees, size);
//...

or you could use a sentinel value at the end of the array and check for it while parsing through the array.

//in function for sorting
void sort(char temp[]);
{
       int i = 0;
       while (temp[i] != '/0')
       {
              // your code here
       }
}

i prefer to use the first case becuase it is much easier for int arrays then using a sentinel.

NathanOliver 429 Veteran Poster Featured Poster

To jBat and invisi I would reconsider your input methods. you are using cin >> val; which will cause an infinite loop to occur if if something other than a char is entered. I would suggest the use of get(cin, val); instead and then convert if necessary. here is a good link on this. http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.2

NathanOliver 429 Veteran Poster Featured Poster

if (answer!=df1/df2) Very scary. You should not compare floating point numbers this way because it will not always work. here is a good link on why. http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17

NathanOliver 429 Veteran Poster Featured Poster

To EngSara and gertails please read this http://www.daniweb.com/forums/announcement8-2.html . This forum is designed to help people find answers not to give them to them. This was assigned as homework for a reason. People must show effort otherwise the learning process does not happen as it should.

jonsca commented: Preach it :) +2
Salem commented: Damn straight! +19
NathanOliver 429 Veteran Poster Featured Poster

well first of your calling getline twice. once after your for statement and once after your if statement. also you should not use eof() while reading to the end of the file. you can search around and find some good links about that. i would get rid of the for loop and just use a while loop like

while (getline(ifs1, s1) && getline(ifs2, s1))
{
       // your code here
       i++;  //  this will increment i so you don't need the for loop.
}
NathanOliver 429 Veteran Poster Featured Poster

yeah your setting a pointer equal to another. classes don't need an operator=() function for that its handled by the compiler.

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

the 1120 error comes from the 2019 error. if you get a LNK2019 error you will always get a LNK1102 error

jonsca commented: Good insight, I had forgotten +2
NathanOliver 429 Veteran Poster Featured Poster

you have no braces around your while function. should be

while (i < NUM_EXAMS)
{  // <-  dont forget these for multy line statements.
        input >> examScore[i];
        sumOfTheScores += examScore[i];
        i++
}  // <-  same here.
richman0829 commented: Good catch! +1
NathanOliver 429 Veteran Poster Featured Poster

the easiest way to handle all different types of inputs is to receive them as strings and then go through them and figure out what the user entered. there are plenty of functions to help with this. the function isdigit() will test to see if the character is a number. isalpha() will test if its a letter. these functions are defined in the header <locale>. a little demonstration of receiving input as a string and converting it to a number is:

#include <iostream>
#include <locale>
#include <cstdlib>

using namespace std;

int main()
{
       int i = 0;
       int numberInput;
       char input[80];  // used for the user input
       char converter;
       cout << "please enter a number: ";
       cin.getline(input, "\n");  //  receives the entire input into input
       while (isdigit(input[i]))
       {
              converter[i] = input[i]
              i++;
       }
       convert[i] = "\n";
       numberInput = atoi(converter);
       cout << "\nyou entered: " << numberInput;
       return 0;
}

this is just a quick little example of how to get input as strings. of course there are much better ways to do because this wont work with negative numbers. this is just to give you an example how the basics work.

Ancient Dragon commented: Nice answer. +25
Iamthedude commented: Thanks for the assistance +0
NathanOliver 429 Veteran Poster Featured Poster

I'm not seeing a main function anywhere. do you have this code in a main function?

wolfkrug commented: Thanks so much! +0
NathanOliver 429 Veteran Poster Featured Poster

yes the while statement i wrote will check to see if the use entered Y or y. if the user enters either of the toughs the do while loop will continue. all other inputs will stop the loop and end the program.

NathanOliver 429 Veteran Poster Featured Poster

what exactly is you error?

NathanOliver 429 Veteran Poster Featured Poster

here is another solution

double input;
int test;
cout << "Please enter an integer: ";
cin >> input;
test = input;
if (test != input)
{
       cout << you did not enter an integer.";
}

basicaly what you are doing is let the number come in as a double then store it into the int test. if the number is a float then test will be rounded and the resualting if statement will be true and then you will know. hope this helps

tux4life commented: Very nice :) !!! +3
siddhant3s commented: Never compare two floats -1
jephthah commented: this is not a solution, and should not be green. +8