WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ah I see.

Though what i meant was get the same results of the infix notation as in
1+2-3 = 0 <- I can do this
1 2 + 3- = 0 <- I don't know how a computer evaluates this

A computer doesn't evaluate it. A program, written by you, does. You take your knowledge and convert it into a program (like the previous post).

As for your code, without proper formatting I'm not even going to try to follow it. It's hard enough understanding someone else's code without adding the difficulty of no indentation at all.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not 100% sure what your saying. The code I put in the original post IS an infix to postfix converter. I know how to convert infix to postfix and prefix. What I don't know and am asking for is how to evaluate the postfix code like it was in infix notation in C++.

Confused. You can't "evaluate the postfix code like it was in infix notation". It's Postfix. Try giving an example. Words don't always do the job, especially when you aren't even sure of what you're asking.

As in I enter an infix notation equation, it's converted to postfix, and that post fix is evaluated. What I'm hoping for is an explanation on how, in C++, postfix is evaluated. I know the mathamatic way it's done I just can't express it in code.

If you know the mathmatical way, you need to
1) write down the decisions and steps themselves as a guide. This becomes your algorithm.
2) Now break each step/decision into smaller steps.
3) When the steps are broken down small enough, use the steps to evaluate a few equations. Make sure the steps are in the proper order to evaluate your equation.
4) This is when you can translate the steps into code. Just follow the roadmap you've created.

This is how programming is done:

Design (1), no computer involved.
Plan the process (2)
Verify the process (3)
Code (4), where the computer finally comes in.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This is homework, isn't it...

If so, aren't you supposed to learn how to actually do postfix notation, and then be able to program it? First thing is to understand what postfix is, and how it works. Reading someone's code is not the way to learn it.

Do you need to find some good explanations on how to understand postfix and it's evaluation?
Start with http://en.wikipedia.org/wiki/Reverse_Polish_notation

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The code below takes an entered infix and converts it into a postfix but I don't know how to take that postfix and evaluate it. Every single tutorial I've seen evaluates a postfix entered directly instead of a infix, so I have no clue what to do.

I don't understand the problem. Postfix is Postfix, isn't it? What's the difference between entering Postfix directly, or having Infix converted to Postfix and using that?

Think about it this way. If you're making spaghetti and you need tomato puree, does it matter whether you open a can of tomato puree or you open a can of whole tomatoes and puree them in a blender?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why are there so many worthless posts here? The answer is extremely simple:

There is no function (why would there be?)
Use = on 2 consecutive characters.

Here's the answer plus it has a string function

We don't give answers here. We help them fix their attempt.

As for your code: main(){ -- main is always an int scanf("%s",string); -- see this for(i=0;i<strlen(string);i++) -- why calculate the length of the string every time through the loop? That's a waste of resources. And why compare the last character with the \0 at the end? if(string[i]==string[i+1]){ -- indent properly printf("%c\n", string[i]); -- indent properly
where's your required return statement?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Don't us char, use string

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What do you think? ;)

I think ... you're letting your 3-year-old daughter answer the question! She's prob'ly smarter than any ol' bot anyway!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sounds like you need to learn some coding techniques. "just throwing codes together" rarely results in a working program. And "I believe I have the function that inputs the trapezoidal rule correctly" is also a recipe for disaster. If you don't...

Questions:
1) Can you solve the equations by hand?
   a) If not, you need to figure this out. You can't program what you don't know.
   b) If so, write down the steps (in words) you take to solve it. 
      This is partially where your [I]code[/I] comes from.
2) Can you test your function with known values that have a known answer?
   a) If not, you will never be sure if it's right or not.
   b) If so, good. Do it.  
      Test as many possibilities as you can. They [B]all[/B] must work
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Threads don't close unless they cause problems. But when you finish your task it's proper to "Mark this Thread as Solved", above the reply box.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is the following easier to read?

Much!!

Hey all. I'm trying to get the FindDaysOver function to grab the avg result from the CalcAvg function result in main. What am I doing wrong?

Nothing that I can see.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thanks to your formatting your code is extremely difficult to read. I can't even find FindDaysOver()

Reformat using this link and repost.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No. We have a 1 in 50 chance of picking the correct line the error is on.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

catalog[x,0] is not how you specify a 2D array.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The first index needs to be specified: string catalog[5][] = {...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

that all depends on what the errors are since you didnt bother to tell us what they are we dont know what to look for you cant just drop code on us an say fix it you have to xeplain what the problems are because we arent compilers were human

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

[boilerplate_help_info]

Posing requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry for the downvote. I'll get it cleaned up. It was the double post that threw me.

The solution you came up with is far superior to the suggestion.

*EDIT*
Just a final little question to be clear, after I use '>>' to grab the FIRST_NAME and LAST_NAME from the input file, does the '.get' start getting input characters after LAST_NAME has been grabbed? This has always puzzled me, whether '.get' keeps count of its position with relation to previous uses of '>>'. It would seem to make sense that it does, since the characters from FIRST_NAME and LAST_NAME would mess stuff up, but I would like to make sure of this.

Output the value from the .get and see what you have. If you ever have a question like this, your best and fastest solution is test it yourself with a small test program.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Good.

By the way, you can make these IFs simpler:

if(90 <= avg)
letter = 'A';
else if(80 <= avg && avg < 90)  // for this if is it even possible for AVG 
                                // to be >= 90?
letter = 'B';
else if(70 <= avg && avg < 80)  // Same here with 80...
letter = 'C';
else if(60 <= avg && avg < 70)
letter = 'D';
else
letter = 'F';

Also if(90 <= avg) is confusing to most professionals. if(avg > 90) is the (unwritten) standard format. But this is not set in stone.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Obviously. But why?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry, I am having trouble understanding what you are trying to say. Do you suggest that I insert

cout << avg << endl;

after the for loop? Or are you saying that there is a mistake within the for loop?

Really? OK:

Print out just that piece of code -- the loop.
Sit at your desk.
Put that pice of code in front of you.
Pick up a pencil.
Write down some numbers labeled FILE that will be the values of the 'file' you are going to read (based on your assignment). Use only 3 students for this.
Looking at those numbers, what should the answer be for the class average (based on your assignment). Write it down.
You can also calculate each student's average. Write them down, too.

Now, start with the FOR statement and write down num = whatever num is (from 'file' -- it's 3) grade = 0 since that's what the FOR does
Go to the next line and "input" (write down) a value for score1[grade] (the first number from your 'file')
Continue to the next statement and do what it says.
Keep doing this until you have finished the loop.

What's the value of avg? If avg is correct, you didn't follow your loop as written. If avg is wrong, why? If you don't know, do it again and really look at what you are doing.


As for "And please learn …

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

but what is wrong with my code???

Don't know what to look for. We have no idea why you think the code is wrong. You didn't explain it to us.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And your question is?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Take this piece of code:

for(grade=0; grade<num; grade++)
    {
    inp1>>score1[grade];
    inp2>>score2[grade];
    inp3>>score3[grade];
    avg=(score1[grade]+score2[grade]+score3[grade])/3;
}
cout<<avg<<endl;

Run it by hand on paper for 3 students. What does avg display?

Be sure you execute each statement exactly as written, not as you think it should be.

And please learn now to format your code properly. It helps us help you, and you yourself can see what's happening easier.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why not use new? It's C++ whereas malloc() C.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So if it's solved, mark the thread solved!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If he's having trouble reading a file and looking at the words, and won't post code
1) what makes you think he's been taught vectors?
2) why are you the one posting code?
3) why are you doing his homework for him?
4) why are you using a bad form for your loop counter that is a logic error?

All in all, two very bad posts.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's not jumping out at me (although I have my suspicions). What I'd do is
1) change the outputs from Fout into cout so you can actually watch the program as it executes.
2) add more cout statements and display values as they are read and calculated. See if the values are correct as the program progresses.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And what is your problem now? And please fix your formatting for the next post. The code is very difficult to follow.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What happened to point 2? It specifically mentioned CODE Tags. And proper formatting. You used neither.

As for your code, so many problems!

ifstream Fin;
	ofstream Fout;

Fin>>FName;     // Where are you inputting from?
Fout<<Name;     // 1: Where are you outputting to?
                // 2: What value are you outputting?
while(!Fin.eof())
	{
		do{	
		Fin>>First_Name>>Last_Name; 
		Fout<<First_Name<<" "<<Last_Name;
		Fin>>Score;         // Are you doing anything with this score?
		}
	  while(Score !=-1) ;  // What is this DO-WHILE really doing?  Work it out.
	  Fin>>(Score);
	  Sum += Score ;
	  Test_Number++ ;
	}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

[boilerplate_help_info]

Posing requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]To [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You do NOT need fseek() . At the beginning of the program, read the data into an array of your CURRENCY structure and you are done with the file. Then you can process all the data you want.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1. the last line is cut off

What causes you to exit the loop? Have you already output all the data when it exits?

2. not sure if i need to have < 20 or <= 20 for the limit.

Then you'll have to make a decision... There's an easy way to find out :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What?? Even I didn't understand what you guys said!

You are printing the address of the pointer to the string.

address 65521 contains the pointer to the string "one"
address 65525 contains the pointer to the string "two"
address 65529 contains the pointer to the string "three"

Change the line to be: printf("%u %u \n",&argv[i], argv[i]); or better yet printf("%p %p \n",&argv[i], argv[i]); since you are displaying addresses. argv[i] is the value you are looking for.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to do a lot more desk work designing the program. You cannot design, write code, and think all while sitting in front of the computer.

Away from the computer, write down the description of the task one line (sentence) at a time.
Take the first sentence and break it down into smaller pieces, or tasks, that need to be done. Do this for each sentence until you have a list of individual tasks.
Put each small task into an order that makes sense so if you gave the list to someone they could draw the pattern just by following the instructions you gave them.
Now, look at each task -- write down an explanation of how it would be coded.

The above is how programming is really done. 80% of the work is non-computer designing and planning, 15% is typing in the code, 5% is looking for the typos when it doesn't compile.

Once you get it to compile, the last 90% is debugging. :icon_wink:
This is where you follow the program with your design and figure out where
1) the code doesn't follow what you designed
2) where the design was wrong

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Anytime :icon_twisted:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First and foremost, learn to format your code. It's terrible and unreadable.

Second, asking for help using lol, idk, XD, and x.x gives us no information other than you spend too much time talking to the computer and not with real people. These are unnecessary and annoying computer geek jargon.

Third, you obviously didn't sit at a desk with pencil and paper to analyze the task to be accomplished. The more you understand the task, the easier to program it is. That means if it takes you 6 hours to program something start to finish,
a) the first 3-1/2 hours is at a desk understanding the task and planning the code,
b) 30 minutes programming the code,
c) 2 hours running and debugging to make the code perfect.

I remember one programming task I had I spent 4 hours understanding and planning the code, 15 minutes typing to code in, and 2 minutes fixing the one and only error - a typo. Any guess how long it would have taken if I sat down at the computer and just started programming?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I already gave you the solution. You still went elsewhere to use someone else's code. Is Accelerated C++ teaching you to steal other people's code to do the project or are you supposed to actually think and come up with your own solution?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sort the values
Copy only the first of any duplicates to a new array.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry, I didn't realize your floats were being read into character arrays. Of course they should be read into floating point values, not characters! Doh!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Major problem #1
Executable code does NOT go in a header file. They go in .C file
Variable definitions do NOT go in a header file. They go in .C file

I'd fix these items first.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The telltale sign of a student programmer is a statement like

if(id >= MINID && id <= MAXID && exam1 >= MINEXAM && exam1 <= MAXEXAM &&
exam2 >= MINEXAM && exam2 <= MAXEXAM && exam3 >= MINEXAM && exam3 <= MAXEXAM)
    return true;
else
    return false;

Which is mostly unreadable.
Split the statement into multiple IFs and return false if any IF is FALSE. If they are all good, return TRUE.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Instead of outputting a SPACE, add it to a string.
Before outputting a *, output that string.
Be sure to reset (clear) the string after output.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The errors you described above were just typos. The original while loop was deleted but it was basically the same thing.

You've now seen that posting code that has typos because you didn't bother to check them wastes your time and ours.

My problem lies in that I don't know how to get strings and doubles from a text file

Yes you do. Your code does that.

My original code did compile and opened the file properly but when it entered the loop the program would respond.

Respond with what? If you don't give us the details to make us understand, you're going to waste even more time with us giving half answers and confusing help.

I'm not sure what you mean about not reading in the first letter. Thanks for any support.

What does fgetc(inputFile) do?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why are you reading the first letter of the metal in the while statement? Do you really want the strings to be
luminum
ast-iron
ngot-iron
alleable-iron
ngot-steel
opper
ickel ?

Compare the file handle in these two statements: while (fgetc(inFile) != EOF) != NULL) fscanf(inputFile, "%s", &metalName); I'll bet the program never enters the loop, rather than gets stuck in it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I don't like the function at all. It would be better IMO to read the file a character at a time and watch for the \n rather than reading an entire buffer, finding the \n and seeking back to reset the file pointer. Much less work.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try writing this a piece at a time.
1) Create the pattern
*
**
***
2) Put that in a loop to make
*

*
**

*
**
***

3) Make the pattern
&
&&
&&&
4) Add a loop to make
$

$$
$$

$$$
$$$
$$$

5) Merge all the pieces to create the final pattern. You might have to plan the pattern and code with pencil and paper to get the pattern correct. Don't just try to create it while sitting at the computer. Good programmers to a lot of non-computer work first to plan out the code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So what is the program doing wrong?

(details please)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

2 things:
1) stop using red -- it's annoying an unnecessary
2) format your code better. It's close to unreadable.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I have a bunch of floats and I need to convert them to string to use Send command to send to a Receiver. However, I been trying to code like below where long1deg is a float. char long1degC = long1deg; Or

char* long1degC = new char[30];
 
    float long1deg= 2.4567F;
    sprintf(long1degC, "%.4g", long1deg);

but I always get errors every time. Any pointer will be really appreciated.

unfortunately my psychic powers aren't working tonight so I am unable to divine what the errors are. Maybe you should tell us.

And you should be using CODE tags, not ICODE tags.