WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
cout << "Enter Major: "
cin << major;
major = toupper(ch);
cout << "Enter Threshold: "

How do you get major into cin? Is your << wrong? And if so, check the next line, too.

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

When using >> to read something, Only 1 word is read.You'll need to look at other options for reading multiple-word titles.

One idea is to read the entire line as a string and find the Price, Quantity, and Discount and convert them.

Another idea (easiest) is to reorder the file so the Title is at the end of each line. Then you can read the numbers and then the rest of the line as the title.

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

I've noticed every time someone claims they have an easy or quick question, you can count on a minimum of a week or two of struggle to get the problem figured out.

If it was so easy, why do you have to ask? :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
palindrome(string[1]);

is passing a single character into the function. You probably want

palindrome(&string[1]);

since that's what the function is expecting.

As for your logic, it's a royal mess. You are expecting the entire string to be available in the function, but never really keep track of the locations you are testing. Based on what I see, you are trying to test each character from the beginning with the last character of the string itself.

To do what you are attempting, you probably need to pass in the string (all of it), 0 (first char position), and strlen(string)-1 (last char position) in the initial call. Then call the itself with string (all of it), incrementing the first position and decrementing the last position.

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

Unfortunately, because there is no formatting at all, few of us are going to take the time to find the equations you're talking about in almost 200 lines. Check this out and repost with a little more detail.

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

I see the following problems:
1) Using void main() -- see this
2) Your formatting is terrible -- see this. Without good formatting, code is very difficult to follow.

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

If you also strip out line #17 -- you're doing the output in your searchCount() function now -- you should be done.

Actually, it would be better to strip the output out of the function. Let the function do its job (search) and only it's job. Let main() decide when and if the output should be displayed.

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

Look at the file and the lines displayed. Which lines are displayed?

It looks like you're reading one line, throwing it away, then reading the next line and using it.
This is repeated.
Then you get to the EOF.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
for(i = 0; i < g; i++)
       {
             bdays[i] = 1 + rand() % 365;
             for (j = 0; j < g; j++)
            {
                  if (bdays[i] == bdays[j])
                        return 1;
                   else
                       i - 1;
                 if (i == 0)
                       return 0;
             }
       }

This loop makes no sense at all. Your first step is to format the entire code because it's really hard to see what's going on. I reformatted the loop and it still is senseless.

i and j both start at 0. So your IF is always true since bdays[0] will always be equal to itself.
If the IF wasn't true though, you execute i - 1 which does nothing. Then you test if i is zero, which it is, so you return.

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

please help.

Line 44 is

{

What was it before you rewrite it?

i even change it to this but still getting additional numbers.

Changed what to what? Are we supposed to not only find your bug but also find your changes. And in this unformatted code that Salem already pointed out?

Format your code, ask intelligent questions, don't make us guess, and you'll probably get an answer in 1 post, rather than all this lack of understanding on our part and frustration on your part.

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

If you are trying to learn C++ why are you concerned with making a C program?

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

false and true are not defined in C. You need to define them.

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

Why are you trying to store the strings "false" and "true" into double variables?

And where did you define Printf()?

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

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

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

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

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

I agree.

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

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

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

Add cin.get() just before the return.

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

Threads should remain open as a rule of thumb, and there should be no rule/movement against contributing to those threads at any time provided that contribution is on topic and adds something worthy to the thread in question.

Where the addition is spam/hijack etc then it gets dealt with using existing moderator processes.

Define etc. Does etc include "Me too", "Good code", "Thanks" resurrections, or are they part of the "adds something worthy" form of reply?

jephthah points out, another level of questionable resurrections. In some cases, a post that supplants previously good code with crap. Are they also "worthy" simply because they tried to help?

Here is my biggest complaint. Dani states she wants 'black and white' rules. You can't have b&w rules. What mods need are workable guidelines. If a resurrection doesn't add worth to the thread, what options can we choose from? And yes, sometimes worth is subjective. How do we decide?

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

Thank you that actually worked. I tried single quotes but not double quotes. I don't know why I didn't try double quotes in the beginning.

Programming isn't a trial and error process (at least not with syntax). If you have a string, you know if and when, and which quotes are needed.

Now it compiles but I'm trying to get it to return to the beginning where it ask if you want to enter measurements because as it is right now it just goes right back to asking for name and measurements because the answer is still yes as far as the program is concerned. Please take a look and let me know what I can change.

If you are using the program, what would you expect to happen once you've entered the measurements for the current person?

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

I would like the output of this string to display each word in a column and ignore all punctuation. I have tried including an if statement that tells the string to start on a new line when a space is encountered but I haven't had any luck. Any hints are most welcome.

I don't see any attempt to do what you want. All you did is output the line character by character and never tried to output a newline.

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

Do you mind if i PM you some code (not for a homework answer...)?

Against the rules... And it helps no one else. We are not a personal tutor service.

How can i convert this to binary, or even treat any number in c as binary to use bit operations on them (like 1<<y).

It already is binary. Everything in a computer is binary. Only the output is converted to a human-readable format.

if you have an integer with the value 65 and output it as:
Decimal you get 65
Hex you get 41
Octal you get 61
Binary you get 01000001
Character you get A

Once you grasp this concept you will be ready for the next step.

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

Not even going to bother.

First, format your code so we can read it.
Next, ask a question we can answer. That starts with details of the problem, not just posting the assignment and nothing else useful.

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

Do not post homework problems expecting a quick answer
without showing any effort yourself. This especially pertains
to the software development forums. For easy readability, always
wrap programming code within posts in code (code blocks)
and icode (inline code) tags.

Without posting what you've done, all you've asked us to do is write it for you. If you have a question, post the pertinent code section and give us details of what you're having trouble with.

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

Read the Member Rules....

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

also, facesInhand[numberInHand2][13] is beyond the array. The array stops at 12, not 13.

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

I'll bet its your while (!file.eof()) statement. See this ( .eof() is the same as feof()

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

First thing I'd do is simplify. These two statements llint diff = labs (start < end ? start - end : (start == end ? 1 : end - start)), *genList = calloc (diff, sizeof (llint)); *(genList + i) = i * byWhat * (diff > 0 ? 1 : 0 - 1) + start; are a convoluted mess. Break them into smaller statements so you can see what's really happening. Then if something doesn't work you can display individual components of the equation and see what's going on.

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

if there's a thread that needs bumping, it's this one.

Keep Hope Alive!

NOTE: a 10 day bump.

Nick, you know i love you, man

:P

[EDITED]

nevermind. lets not go there. daniweb is a such a nice site.

and yet you bumped an 11-day dead thread to say that.

now see, this is why we can't have nice things. :icon_frown:

Talking about useless bump posts... I see 10 days is OK but 11 is not.

Yes, I did it too, but I did it once to illustrate a point... :icon_wink:

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

Additional:
Just copy the characters into the character array, adding \0 as the last character.

Remember, in C as 'string' is simply an array of characters ending with \0. It's not a special thing, it's not magic. It's just an array of characters by another name.

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

When I try, for example,

strcpy(str,threeDays[0][0])

I get an error saying "invalid conversion from 'const char' to 'const char*'; initializing argument 2 of `char* strcpy(char*, const char*)' "... :(

That's because it is very wrong. See my other post for a clue.

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

Only if each and every line is exactly the the same length. If they aren't, you have no way of knowing where any line starts.

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

threeDays[0][0] = 'M'
threeDays[0][1] = 'o'
threeDays[0][2] = 'n'
threeDays[1][0] = 'T'
threeDays[2][0] = 'W'

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

I have never posted to a forum before. I am taking a beginning C++ prgmming class.

It shows. You didn't bother to read the Member Rules and made a bad post...

Start by formatting your code so you can follow it. This error is almost always because of misplaced braces and formatting shows very quickly where the error is. It also makes code readable for others (like us) that didn't write it.

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

Every time you use an input statement, you should be checking the return status. Therefore, you should have no problem unless your input file is hosed.

What's the difference between while(infile.good()) and while(!infile.eof()) ? Aren't they (in this context) the same test?

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

EOF means end of file. You can check for it like this:

while(!infile.eof())

You could, but it's not recommended unless you are verrrrrry careful. Here's why.

(feof() and .eof() operate identically)