jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
void Person:: setPay(float thePay)
{
     pay = thePayRate;
}
void Person::setHours(int theHours)
{
     hours = theHoursWorked;
}

Have a problem here with those variable names. Also, does your compiler warn you about iostream.h? Should just be #include <iostream>

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

im a noob, what you mean move those variables into the declaration?

class BankAccount
{
public:
	double enterAccountData();
	double computeInterest();
	void displayAccount();
private:
	int accountNumber;
	double accountBalance;
	static const double RATE;
                   <--------- here
}

You have local variables number and balance that you declare (or attempt to use without declaring) within the functions. If you are going to use them put them up in the declaration (see above) so that they are visible to the methods of the class. Since you have an accountNumber and accountBalance why don't you use those?

Also, Restrictment is right, you either need to be returning doubles from those two functions (so having a return RATE*accountBalance; and perhaps the initial balance for the other one) and handle the changes to balance in main() or leave the functions as they are and change their return type to void . These are design decisions that you will have to make. My vote would be to change them to void unless they are required to return something.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your function calls in main seem ok. You should still be getting some compile time errors, as some of your variables are declared within your member functions (where they cannot be seen within the other member functions) and they should be moved to the public or private section of your class definition.

Also, before I said cin.getc() what I really meant was cin.get(). Apologies. I don't use it on a regular basis anymore...

EDIT: I missed that they are supposed to be returning doubles. Yikes. Well, unless you move those variables into the declaration the whole business wouldn't even compile anyway.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What are the errors that you are getting now?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you need to include more headers... no only kidding. First remove that stray #endif . Then put a semicolon after your class declaration. Get rid off all of the header includes except iostream (substitute cin.getc(); for your conio function). If you are using VC++ you may need to turn off precompiled headers to get rid of stdafx.h. There are a few other smaller errors but those should be easy to find once you get rid of these.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's another inconsistency when you are trying to dereference your struct members to write to them with cin. First, for multiple accounts you are not using the i value anywhere in your loop. So you need x to dereference your array pointer and then you can just use the dot operator, e.g. x[i].name to get the name element.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No worries. Just thought I missed something huge for a second :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

He's not trying to accumulate anything, he does that in his for loop in main. Based on how he's laid it out, he just needs to pass in the heads and tails and get the output.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Start with the first error and go through them one by one. It's just a bunch of stray stuff that you left in during editing. Just go to the lines the complier is complaining about, you'll catch em.
And, you need braces {} around your entire switch block, encompassing all the cases. switch(variable) { //all the cases in here}

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you need to call calculateTotal(heads,tails); from main. As it is you don't do anything with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

should be if(pkg == 'A' || pkg=='B' || pkg == 'C') otherwise they won't match character for character.

Your switch statement should look like:

switch(pkg)
{
      case 'A':  //case A goes here
               break;
      case 'B' :  // case B goes here
               break;
       etc.
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you using Visual C++? If so, did you try to run a debug build on the other machine? If so, you need the release build.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I found this... Honestly I'm not sure I understand it completely.

http://gcc.gnu.org/ml/gcc-help/2008-01/msg00137.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Scratch... sorry. I think he's right with the while, except use your count variable. You were getting stuck since your for loop wasn't incrementing itemsOrdered but even doing that your count would be off. Go for the while or do{} while().

(when writing this I had missed that itemsOrdered was a char, but you got it to work so good luck and hope we at least nudged you a bit in the right direction :) )

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not having the user input them before they are passed into your functions(at least not in this snippet that you have posted, they are there in your other program), so they may never be defined before the function is called. Put in a cin statement to get the values. Temporarily you could set them to a value but that's probably bad practice.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's no such thing as subint to my knowledge.
Take in the ID as a string, do a substr(0,2), convert that truncated string to an integer (using atoi). There's a slight flaw in your ID scheme though since if the digits are 00-09 the person could be 100 or just born. You need to do your subtraction by adding to your year value so it gives the right age.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How did your instructor teach it to you? It's just a matter that variables used within a function are invisible in other functions. When defining a function (e.g. void myfunc(int param1, int param2) ) the variables names in the parameters are the ones used in the functions. So when you are defining cscclass in main and attempting to use it in your function, there is no such variable. It looks like you are trying to pass a struct in but your syntax is incorrect and the name of the struct that you are passing in is not cscclass.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

should be 2*(mps*cos(angle))); in the height_earth function (you left out the multiplication sign)

Like anything else, if this is something you want to be doing you need to work hard at it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In your read_student class above you are passing in a struct and an int. Instead of saying struct pass in an object of type student_data called cscclass so you don't have to change all your functions all around(and still pass in the int of course). It often happens that you uncover more errors when you fix one. Keep at it and when you get completely stuck post back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right, Because...The sin function in the math library uses radians.

cout << " " << angle << " degrees is equal to " << (angrad = angtorad(angle, pi)) << " radian(s)." << endl << endl << endl;
	cout << " The distance traveled on Earth = " << distance_earth (angrad,mps,earth_gravity) << " meters " << endl;
	cout << " The distance traveled on Mars = " << distance_mars (angrad,mps,mars_gravity) << " meters " << endl;
	cout << " The distance traveled on The Moon = " << distance_moon (angrad,mps,moon_gravity)<< " meters " << endl;

to spell it out explicitly...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you call angtorad, but you do nothing with the return value except send it to the output stream. just calling your function does not change the value of angle which remains at the value your user had entered, even when you call the other functions with angle in the arguments.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I didn't check your math....give it a try, as it stands you are not converting your degrees to radians (except to display it on that one line, but the next line you put the value in degrees into your function).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

But why does your function return an int if you want it to return a string? Was your assignment given that way? Just saying it doesn't make much sense. If you need to return a string, just change the return type of the function string myName() { etc. }

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hello guys.. I have this tutorial that i keep getting errors on no matter what i've tried.. Would someone kindly check it out for me?!
Here is the question:

# include <iostream>
# include <string>
void read_student_class(struct student_class[], int class_size)
 
{
	for(int i=0; i<20; i++)
	{
	cin>>csclass[i].studentFname
	   >>csclass[i].studentLname
	   >>csclass[i].testscore;

relevant_grade(student_class[i].grade);
}

Mismatched braces here for starters.

Also, you never explicitly typedef student_data as StudentType.

And why are you passing in something called student_class to your functions and then trying to use something called cscclass which is not in scope within your function? Take a few minutes and read your text section on variable scope.

There are other errors, but just start knocking them out one by one. The scope issues are the major ones.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why can't myName() return a string instead of an int? Also, the restriction on cout seems to be for your function body only.

Great post title, BTW.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Next, since you do not always have 6 teams, pass the number of teams into calculateResults (via an additional int parameter at the end) which can then be passed into sortTable. Don't be afraid to absolutely pepper your code with cout statements to determine where things are crashing, it will help you in the long run.

Still holds. Don't hard-code 6 into your sortTable function. So, sortTable needs the number of teams. sortTable is called within calculateResults, which has no knowledge of numOfTeams either. How can we provide that knowledge? Pass numOfTeams into calculateResults as an extra parameter, then pass it into sortTable. I know you can do this. Go step by step. I cannot in good conscience keep translating these concepts into the code for you. This assignment is for your benefit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Return angtorad into a variable, so say double angrad = angtorad(angle,pi); You never actually change angle when you run your function. Use your new value in place of angle in your other functions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

And, you're very welcome!!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

typedef struct teams; should be typedef struct TeamInfo teams; Change your cout on line 67 above to cout <<variable1<<"\t\t"<<variable2<<"\t\t" etc. etc.

That's what I meant by the above cout<<teams[i].name<< "\t\t" << ETC http://publib.boulder.ibm.com/infocenter/comphelp/v101v121/index.jsp?topic=/com.ibm.xlcpp101.aix.doc/legacy/id00066.html Let the great Google be your guide. Read up on cout and cin if you're still having trouble, but the << and >> operator syntax is quite intuitive, cout << stuff to send stuff to output, cin >> stuff to send input from cin to stuff.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think he might mean a situation where you could take in a class name from the user and instantiate a class, so in your example above:

string classname;
std::cin >> classname;
(it's invalid but...)  classname * cn = new classname();

I think for a finite number of cases you could use a bunch of if/else if statements:

if(classname == "Foo")
     Foo * foo = new Foo();
elseif(classname  == "Bar")
     Bar * bar = new Bar();
...
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Like I had said before, don't make temp an array (it's got one element so what's the point?) just declare it T temp; . Next, since you do not always have 6 teams, pass the number of teams into calculateResults (via an additional int parameter at the end) which can then be passed into sortTable. Make sure you also change the i<6 in your menu item 2 to i<numOfTeams (also like I had said before) so you don't overstep your array. Don't be afraid to absolutely pepper your code with cout statements to determine where things are crashing, it will help you in the long run.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should change teams to something else for EITHER the typedef OR the variable. But leave it as it is for now, and change the declaration of addteam to void addTeam(T *,char[50],int) and the definition to void addTeam(T* T, char*teamName,int i) (first T is for the typedef,*,second T for your local variable in your function). Now, your variable T is within the scope of the function (when you have a free minute reread that section of your text on scope because it's crucial to know).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

yes,these changes are relevnt and i have made thembut still getting errors in void function, maybe problem is in the main()???

Your array teams does not exist in this function. In order to use it you must pass it in. Give your function (both functions, really) a parameter called teams for it to be available in your function body. The type of teams the array is teams* (not to match your array in your function, but to match your typedef up above). In main, you need to change your function calls to reflect the new parameter (which you can pass in as teams, to match your array name) e.g., addTeam(teams,newTeam, numOfTeams);

For your own sanity, you should probably change the name of the typedef or the name of the array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Couple of other little issues: You prompt for a new team twice
In your calculate results you 1.) declare a 1 element array(??) and 2.) you reference it's one element by index 1.
In main change your for loop

else if (menuChoice == 2)
		{
			cout << "\t\tP\tW\tD\tL\tF\tA\tT\n\n\n" << endl;
			for ( i = 0; i < 6; i++)

to i < numOfTeams And change newTeam[strlen(newTeam)-1] = '\0'; to newTeam[strlen(newTeam)] = '\0'; otherwise you are truncating your string

As for the other part, add a parameter teams * teams I renamed it to teams * team and changed all your teams to team to avoid confusion.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

teams is not in scope for either of them. The functions have their own local scope and can't "see" the variables in main(). So, pass the array of structs into each of those, or I suppose you could use your function to return a new struct to be placed into the teams array.

Also, I noticed it before but cin >> newTeam, sizeof(newTeam), stdin; is probably not going to give you what you want, you don't need to specify those values, just take the input into newTeam with cin >>newTeam; .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First, declare ofstream report; within main() so it's not global. Then, for your function output_info, pass report in by reference (so you'll have to change your declaration of output_info to report this). Make sure you do the opening of your file within main() first before you pass it into anything.
Now anywhere there is a cout at the present (so cout << "ID number:"; becomes report <<"ID number:"; . Any other functions that need it, do the same thing, pass that ofstream report in by reference.

The direction of your << or >> operator should reflect whether you are taking data into a variable from a stream or outputting to a stream.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just change ph to an int (it doesn't work because 10-14 aren't chars, they are strings)

And you're missing a semicolon after cin.get() and you need to close your switch statement with a brace

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It requires you to hit enter twice, but put a if(Ch == '\n') break; before if(isdigit(Ch) and change EOF in the outer while to '\n' . I'm trying to think of another way to do it that's more elegant but that works.
Also, it's interesting (I'm not sure why) but it takes like 30 seconds on my machine (of less than a year) for the program to start accepting the chars I put in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should just be able to substitute your ofstream object for the cout directly. See http://www.bgsu.edu/departments/compsci/docs/write.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're program is trying to get 20 sets of data after 20 different decimal points. I don't think that's what you want. You could move k into your inner while loop to keep track of the total number of digits.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

declare a variable as count at the top of main (what would be a good type for that variable if it's going to hold 0,1,2,3...), set it to zero. Each time your condition is met (so when your if statement is saying yes, the users input has matched the desired value), increment your counter (that is, assign the value of variable+1 back to variable).
At the end, cout << count<<"/3 \n"; If you get stuck, post back, but flip ahead a few pages in your text too. I know you may not have covered the topics yet, but you probably can create it out of stuff you are already familiar with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put a counter in with the (appropriate) if statements you've already defined (when a match happens, register one more on the counter). In the end, output the counter.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is the best self-contained list I could find: http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier
They seem to cover the ones I remember.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

typedef struct teams; should be typedef struct TeamInfo teams; Change your cout on line 67 above to cout <<variable1<<"\t\t"<<variable2<<"\t\t" etc. etc.

There are major issues with scope too but grab the basic stuff first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your while loop is fine. I would ask yourself if 6 people came up to you and handed you a card with a number on it, how would you tell if the numbers fell into those categories. Hint, can a number be both less than 10 AND greater than 500? No. Those are the two things you are measuring. There are a number of different ways to test for it but just break down the logic, is this less than 10? No. Is it greater than 500? Yes. Ok, we don't care how many times this condition comes up, just switch the flag to true. Are there any values that are less than 10 OR greater than 500.... Just write it out the logic on a piece of paper and translate your words into the appropriate code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

cout << setiosflags(ios::fixed) << setprecision(2); Sets the display to fixed precision and then fixes the number of digits after the decimal to 2. Any calls to cout after that will have those properties.
Use resetiosflags (http://www.cplusplus.com/reference/iostream/manipulators/resetiosflags/ ) to restore the default settings (it might not reset the 2 digit portion, I'm not sure)

P.S. you need to include <iomanip> for the above

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Explain your confusion a little more. Wouldn't you just add up all of the product[index].sale values then prompt the user for a payment amount?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are calling your functions with the proper parameter, but the return value is disappearing

So back in main you need something = circ(radius); This function has an output, you need to hook it up to something.

Also note that the circumference variable in the main function is completely unrelated to the circumference you declared in your function. Take a look at your text's treatment of the scope of variables.