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

Your get_days_in_month() has a major problem.
You malloc() the day array but never free it, creating a memory leak. You'd be better off just creating the array as a pointer in the main() function.

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

Use the number of the node as part of the file name. File for Node 4 is Node04.txt for example.

If you know stringstreams, you can generate the filename that way. If not, you can use ssprintf() . Include the cstdio header.

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

I got the answer

But your ending loop is too complex.

while(ans!='n'||ans!='y')
{
  cout<<"enter only y or n";
  ans=getche()
  if(ans=='n'||ans=='y') 
     break;
}

If the while statement is supposed to exit when Y or N is pressed, why the if statement that breaks out of the loop? Get rid of the if statement and let the while do it's job.

Basically, a thing that you need to understand is the fact that

while( ans != 'n' || ans != 'y' )

is effectively the same as writing

while( true )

And there is no way around that. :)

That was why I suggested a Truth Table... :icon_wink:

Here was my interpretation (I reserve the right to be wrong, so I'm just seeking for my own clarification here, so I'll beg the OPs pardon)

ans=getche(); //user inputs 'g' <enter> (only room for g in the 'ans')
if(ans!='n'||ans!='y')   //this is true
        ans=getch(); //I was saying enter gets picked up by this
                //apparently that's not the case?

No, getche() and getch() work the same way. Hit a key and the program continues. You won't get a chance to hit the ENTER.

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

1) Why don't you output angle and coeff when you read them in? Make sure they are correct.

2) Why are you setting max and min to matrix entries that have not been read yet? Set them after the matrix is loaded.

3) If the file error message is displayed, why do you continue as if nothing is wrong? The rest of the program should be in the else condition.

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

So mentioning that it's not the compiler's fault when it is clearly the programmer's lack of knowledge is not constructive? Sorry. My mistake.

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

I repeat:

>>How to fix the problem, please?
what problem??

You must tell us the problem. Do NOT just post code and ask us for a solution .

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

so would I use something like fgets instead?

Didn't the link offer a replacement?

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

Do not use scanf() to read strings. Here's why.

So how are you going to check for letters when you left all the other inputs to read integers only? They will still cause problems.

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

Yess suh, masta. I'z chilled.

You obviously know better than the rest of us. Sorry.

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

Put in a cin.ignore() after the ans = getche(); line. The newline ('\n') from the when you entered y or n the first time was staying in the input stream and getting picked up by the getch() which took it as input and moved on. I don't know offhand if the cin.ignore() plays nice with the conio functions.

That being said, I would avoid the conio.h functions unless it's absolutely necessary to do so. Use cin.get() or getchar() (getchar requires <cstdio>) for portability.

There was no \n left in the buffer unless it was before the do-while . getche() is the same as getch() with echo.

But, I agree with jonsca about not using conio.h functions. They are non-standard and not used in the industry.

Looking at your IF statement, put it in a truth table. You will find it will always be true.

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

What constitutes the end of a sentence? Look for it and set a flag for EndOfSentence. Then next letter you find, capitalize it and clear EndOfSentence.

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

Actually, there is no iostream in C. It is a C++ feature, and certainly is in Dev-C++

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

You can't use a string object with strcmp() . 2 solutions:
1) use the compare method that's part of the string object
2) convert the string object to char* with stringname.c_str()

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

The way to accomplish this task is to input everything as string. Then check the string character by character to make sure there are no bad chars entered. Then convert each value in the string to integers.

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

Where did you check for 'e' and 's'? There is only a check for 'y'.

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

In general

for (i=0; i<10; i++)
{
    ....
}

becomes

i=0;
while (i < 10)
{
    ....
    i++;
}

In other syntax:

for ( A; B; C)
{
}

becomes

A;
while(B)
{
    C;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up the functions isdigit() and ispunct() in ctype.h or cctype headers.

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

Since I'm not an accountant and I don't know the equations themselves, I can give you basic ideas on the program flow.

Ask for:
Total to borrow (principal)
Interest rate (interest)
Length of loan (length)

With those 3 you can get the minimum monthly payment using one of the equations.
Ask for the payment they want. Of course, this will change the length of the loan, so you won't need that anymore.

Now start a while loop until principal <= 0
Calculate the payment on principal.
From that get all the other values for the month (interest paid, new balance, accumulated payment and interest)
Print a line of your amortization chart.

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

I need help figuring out why it doesn't work haha.

then tell us what it does wrong, haha. We aren't psychic, chortle.

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

Changing it to use a human player simply means that any information that the computer player generates must come from the keyboard.

Where in the code do you generate the data for a player's move? Take that code and put an IF (player == computer) statement around it. Then make an else to accept input from the user.

Be sure to make a variable to keep track of the type of player, or make, say, player 1 always be the human. Change the IF accordingly.

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

Please format your code. It is really difficult to read and follow.

Because I can't read the code, I'll make a guess. You are defining an array of pointers, and attempting to stuff data into the pointers. But there is no data space defined. Just pointers. That will cause your problem.

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

input is not data. It's your ifstream object.
You haven't defined a 2d Matrix to hold the input.

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

the i in itoa means integer I think...

And what type of values are you using?

also, what if the equation has more than one operation? like:
7+5*9

If your math teacher gave you the exact same equation, what would you do? That's what you teach the computer to do, also.

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

http://www.youtube.com/watch?v=FjqkH-rekiQ

I laughed, and then I asked myself, did they just dodge the question?

I like that one!!!

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

My point is

...
And you need to tell us what help you need, otherwise you'll just get more code written by more people.

And we're not going to write your code.

And let me guess, you wrote AMICABLE and HAMONIC...

jephthah commented: for such a passive-aggressive snark, you need to step off my nuts. -1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'd be more interested in knowing why you need seekg() . This doesn't look like a binary search. Just looks like you're bouncing around a file for the sake of bouncing where just reading the file would be more efficient and less error-prone.

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

I agree.

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

First off, the include file should be includs, not includs.cpp

And it has to be included in each file that needs it.

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

You have a wrong concept IMO.
When you input a number, convert it to double. Keep everything as a double. When you output the answer, just output the double. You want to stay away from strings as much as possible after the initial input.

Also, any idea what the i means in itoa()? Which, by the way, is not a standard function.

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

You have a great idea -- Add code, test often, move on. And your formatting is really good. And comments! Wow!!!!

When asking for help, a blanket "help me" is not good enough. You need to point out what you need help with and describe what's not working. In detail.

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

My first question is who wrote these programs for you? They are all written by different people. Is your project supposed to copy code from someone else?

And you need to tell us what help you need, otherwise you'll just get more code written by more people. Not a good way to become good at programming. Management, yes. Programming, no.

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

-- wrong, oops ---

And please format your code. It's very hard to follow.

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

Thank you for your response. It now prints the Total Interest, it shows it as a running total. My aim is have the pgm show on the screen the last payment amount and the total interest pd over the loan. In the file all I need is the total interest that was pd. I don't know if it helps but I'm including the full code for the pgm.

Where did you calculate the last payment and total interest? What variables did you use for them? Just output them.

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

That'll teach me to look first...

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

What are you missing in your display?

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

What I am hinting is that, if the problem is only with the first input, there may be a problem with getline function in whichever compiler or platform you're using..

hey thx for your help but it was the compiler's fault. all i need to add in before my first string was cin.ignore(1);

Interesting that lack of knowledge of C++ input means the problem is the fault of the compiler. Sorry guys, it's not the compiler. There are gaps in your understanding. But don't worry about that. You'll fill in those gaps as you go. It is complicated.

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

Not a car guy, eh?

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

Nice. Try it with the city Des Moines or Los Angeles and let us know how it works.

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

Why are you putting a for loop inside the while loop? The for loop will get in your way if there are less than 8 values.

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

Add cin.get() just before the return.

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

If you can't tell if it needs improvements, how can we tell?

When posting code/questions, you need to tell us what you need help with, not leave it to us to figure out if something is wrong.

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

Your program is backwards. You want to
1) start a loop
2) ask for input
3) use the switch
4) continue with loop until exit command entered

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

Is ratings a string, a char array, or an integer?
Therein lies most of your sort problem. You can't use chars to check > the way you are trying to.

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

I have an output function that is how I know that the functions are not working.
what I don't have is the knowledge to know why these are not working, people on here are just like my teacher, they think answers are just going to pop into your head all of the sudden. I have been trying to do this for like 5 hours each day for the last 4 days. Probably like 8 today. That is why I tried to expand my number of resources and ask for help. But everyone just says to figure it out.

I never said "just says to figure it out." you are getting confused because you aren't sure what you are doing and you're trying to to 10 things 10 different ways at once. That's why I said

  • do 1 function.
  • we can help with 1 function
  • you get it correct,
  • you understand that one function
  • the rest are easy

That's teaching. But why you think we are here to teach is beyond me. We're here to help, not teach.

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

I have been trying to do this assignment for the past 4 days. I thought I was doing good but the functions seem to be screwing up. All the greater than and less than functions are messing up. Also the add and subtract functions are messed up. Any suggestions would be appriciated. Please help me and thanks in advance for those that do.

Start over.
Write the input section of the program first. Get it to work.
Then the output section. Get it to work.
Add 1 and only 1 function. Get it to work.
Add one more function. You can probably base it on the first function since that one works.

Continue....

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

When you write to 'buffered' device, sometimes the system will hold the characters in the buffer until a specific thing happens:
1) the buffer is filled
2) a NEWLINE \n is added
3) an explicit command (flush) is used
It all depends on how the compiler I/O is designed.
So on some compilers, a printf() or cout command may not work immediately. Therefore, you flush the buffer when you need the output right away.

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

Stop writing code that causes C2664 and C2562 errors would be a usable suggestion.

That might mean looking up what the errors mean and either memorizing the descriptions & sulutions or writing them down for future reference.