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

I think you need to explain in more detail.
What are you ultimately trying to do?
What is wrong with the two functions?
What is your definition of an invalid input? ... valid input?

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

Can't read it. After 140+ posts you should understand formatting by now.

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

If you aren't going to try what I suggested, I obviously can't help you.

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

Now why would reading your character string ID using a floating point format help? Please explain. Are you planning on using math on this number?

Keep it a char array -- it's not really a number, it's an ID.

Did this mean anything to you?
Why are you mixing C++ I/O (cin, cout) with C I/O (fopen, printf, fscanf)???
It doesn't look like it.

Step back. What is the format of your input? Is it separate values (separated by SPACEs)? If it's not, you are making it hard to process.

If you need those underscores between the fields, fine. Read the entire line as one string and move the fields one character at a time into the field variables (ID, genre, name...). Be sure to add the '\0' before moving on to the next field.

Print out before, during, after to make sure things are going right.

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

I would grab a piece of paper and a pencil and start here:

int value = 0; 
int count = 0;
int sum = 0;
int average;

Write down the above variables on the paper and their values.
Then continue looking at each line of code and change the value of each of the variables:

while (value >= 0)
   {cin >> value;
    sum = sum + value;

So change value to a number you decide to input.
Change sum accordingly
Be sure to "input" different numbers and your negative number as you run through these steps. NOTE: only ONE (1) number per cin...

    count++;
    count = count - 1;

change count accordingly

    average = sum / count;

change average -- is this right? what is an average? the sum of what?

    if (value < 0)
    {return average;}

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

Let's see if you followed the assignment:

Specicially we want you to write a function named generateRandom that generates a single random number in a range specified by the user.

Look at the generateRandom() function. Does it in fact generate any random numbers?

Write a main function that tests this function by:
1) Asking the user for an integer with which to seed the random number generator. Call srand with this integer.
2) Ask the user for a lower and upper bound for the random number.
3) Asking the user how many random numbers to generate

Did you do each of these three things?

4) Call generateRandom the requested number of times and prints the generated random numbers.

Did you do this properly?

You need to be much more careful when you program. Take each step one at a time and program that step before moving to the next step. Don't lump them all together to and try programming everything in one go. That's where many mistakes happen.

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

And why are you calling the function randomize and srand()?

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

Took me a while, too. 32 is not thirty two. It's 3 squared.

Jeez, explain stuff when it's not obvious, people.
9 = 32 is NOT obvious.
8-|

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

After 5 years, we figure the thread is dead so we don't have to jump on if. Now if you asked a proper question by starting your own thread you'd probably get a good response.

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

And main() is NOT void. It's int.

richieking commented: Read well in the future the post and ake sure that you see the similarities before flagging bad post. i dont want to do this but you refused to read carefuly the(my) post before you flagged. -1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Me:
Count the A's, SPACEs and -'s in each line, and in each section of each line.
Look for numerical patterns.
When you see the patterns, write down some calculations that you can turn into code.
Use lots of paper, and analyze analyze analyze. Plan plan plan.

You'll need a few loops for each line.

OK, I guess you don't have to do any of this. Just convert Lucaci's pseudo code into real code. He did the hard work for you.

Be sure to thank him.

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

Count the A's, SPACEs and -'s in each line, and in each section of each line.
Look for numerical patterns.
When you see the patterns, write down some calculations that you can turn into code.
Use lots of paper, and analyze analyze analyze. Plan plan plan.

You'll need a few loops for each line.

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

The vertical spacing is bad, and we can't use it 'in context':
cx += testval is the way to add to cx

This thread is what prompts the request.
Normal CODE Tags are too limiting -- I didn't want to use them as a hack.

Inline CODE is still code - by definition. Spacing should be honored.

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

Format your code!!! You know better!

It's a circular queue. front and rear would be independent of each other. You've tied them together messing up the contents of the queue. But the idea is correct.

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

I repeat: format your code

Yeah, why is ran a double? chaau is correct. I missed that.

And that code is not quite what I suggested.

I am now confused. And I'm partly to blame.
If error = true, stay in the loop. If error = false, exit the loop. For the current use of the variable, it should be named exitLoop

Also, you do not want to exit the program in the loop. You should let the exit happen naturally at the end of the program.

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

Good for you. Have fun.

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

Then we need some way to post lines without stripping spaces since we cannot use CODE.

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

You can now boast about how Daniweb has more than a million members!

"DaniWeb -- the MacDonalds of the cyber universe!" :-)

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

1.how can circular queue can be implemented in a normal linked list??i think it can be implemented in circular singly linked list right??

Right

2.if i implement it in array how i will connect last element with first element????

When you reach the last element of the array, return to the first element

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

(-8 One sentence? Haven't you heard of periods and commas? Sheesh! 8-)

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

You pass the ifstream and ofstream variables the same way you do the int values.

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

Inline Tags need to keep spacing for 2 reasons
1) they are the only way we can officially quote code
2) whether one line or an entire block of code, spacing can be important. It's CODE after all.

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

No, it won't work that way.

Since you open the file(s) in main(), you have the file pointers in the fstream values. These are the values you pass to the functions. That gives the functions access to the files.

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

Does it makes any sense ?

Yes it does. At least to me. My understanding is this loop is the input for the menu, not the entire program.

If the user types anything except 1 or 2, this error loop is supposed to continue asking until a correct response is made.

When the loop exits (1 or 2 was pressed), the program will either
1: do work
2: exit

Kanown:
Always format your code. Always.

cin>>ran;
if(ran==1 || ran==2)
{
    error=true;
}
else
{
    error=false;               // 'error' is already false. 
    cout<<"wrong input";       // That's why you are in this loop
}

Note the comments...
See this about system("pause")

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

you: Do you suggest maybe using a stack especially when you say 'replace' and just insert the answer back in the equation? And you can then more easily get lets say the 'left' and 'right' integers of the '+' sign?

Or did you just use the string?

As I said:

me: Everything stays in the string.

Reread my post.

you: The thing is the equation is not being inputted, I'm receiving it from a predefined string in my main.c

Then you'll have to copy the source string to another string so it can be modified. This is a good thing.

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

Appearently you fail to grasp anything so I make it clear: In case it wasn't obvious in the other thread I don't agree with not posting solutions so this was formulated in that specific way as a slight ridicule towards it.

Ahhh, I see now. It's Mr. "I Know More About These Forums Than Everyone Else".

Problem with your logic is:
1) you are expecting us to remember one post you made elsewhere out of hundreds we read daily
2) sarcasm requires knowledge of the one making sarcastic remarks. All I understand is from what you posted above.
3) on a forum, a smily generally hints at sarcasm. No smily, you must be simply daft.
4) whether you agree or not, you are not to post working answers. Period.
5) better reread the member rules. They are important here, whether you agree with them or not.

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

1) See This
2) Not really. Since you know the start and length, you can easily copy the string out. The function strncpy can do it if you understand derefrencing and indexing.
3) temp[0] = '\0'; -- you set the first entry to 0.

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

First problem I see is the use of GOTO. You should rework the program to use loops instead.

Since there is absolutely no context, no comments, and no explanations of what anything is in the code you posted, there is nothing we can tell you about your code.

I can only suggest to solve the duplicate problem is create an array of 26 values representing the alphabet. Zero the array. Every time a letter is guessed, check the array. If 0, change to 1. If not zero, it's already been guessed.

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

1) Get rid of system("cls"); -- it's verry annoying to the user.
2) Do not use goto -- you don't need it. Use a loop if you need to repeat somthing.
3) You logic is all messed up.

a) You start by setting error to FALSE
b) Then you check the value of ran which sets error to TRUE (it's 0)
c) You input a new value for ran
d) You unconditionally jump above the loop.
Why do you have a loop at all? You never use it.

Try this:

Set error to TRUE
Start while() loop, exit if error = FALSE
    input ran
    if ran = 1 or 2 set error to TRUE
      else output  error message
end loop
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I would suggest you work out how to read the file first. That seems to be more important.

Why are you mixing C++ I/O (cin, cout) with C I/O (fopen, printf, fscanf)??? Your program is quite schizophrenic. It needs a psychiatrist. Decide on what style I/O you want and stick to it.

And get rid of conio.h. You do not need it!

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

It's your job to write the code. I gave you most of what you need. You need to do the rest.

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

So what doesn't work? You need to give us informations if you need help.

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

don't know why but it doesn't work for me

What doesn't? Exactly what did you do?

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

That's because scanf() stops reading at spaces. You'll have to use something like fgets() or a complex/convoluted format specifier in scanf().

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

Not complicated. Just non-informative.

You know what you need to do but we haven't been helping yet. So we have no idea what any of that means. You need to explain your project in enough detail for someone new to understand.

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

To be honest, I'd use a file management program like ZTree. This is something I do quite often and ZTree makes it extremely easy.

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

Meaning what?

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

Are you sure what you typed in (not put, by the way) is correctly in the variable ID1?
Are you sure what you read in from the file is correctly in the variable ID?

Print them out and see. Or use the debugger.

Ps: I'm using Turbo C, because thats what my teacher uses, and he won't accept any programs made In another compiler, such as Dev c++ for example, which I prefer for that sake.

You don't have to keep apologizing for things. You didn't need to rewrite your program into English, and no one said anything about not using Turbo-C.

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

What if the 1,000,000th is a spammer? Do they get a case of jellied pork parts?

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

Im sorry, I forget to rename the code, I'm from venezuela, so I wrote It in spanish. this is the translated code.

That was unnecessary. I understood enough to see what you were doing wrong -- hence my response.

This is part of my code, since my program has such things as, create a file, store data in such file, read all the info In that file, and so on... thats why I didn't put the headers I was using, anyway this is pretty much how the main looks like.

I see you understood my previous post. That's good.

Hope you guys can help me out.

With what? You didn't mention there were any problems.

The only thing I see is you are using conio.h. Don't. It's not portable and once you learn to rely on it, when you change compilers you'll be crippled.

Also, main() is an INT. Most good compilers won't compile a program that don't use a correct definition.

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

First, don't use a double. It's inaccurate. A long is good for 4 billion values. A long long (assuming it works) is astronomically larger.

Second, take that hellacious equation and break it up into manageable segments.
Calculate the year. Then the month. Then the day. Then put them together. This way you can output intermediate values to see if they are correct.

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

Format! Format! Format! Format! Format! Format!

gets()

Isn't ced your ID?
Isn't it a char array?
Why are you reading it as a float?

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

Why would it round down though? 0.52*100=52 not 51.

Because

Once the input exceeded 1.00 it got rid of the rounding error, or perhaps I didn't check enough of the inputs to verify.

You didn't check enough inputs.

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

Probably because loops are still too hard

He's using loops now.

I would say he's learning loops now ;-)

I never mentioned vectors or any higher level stuff, just recursion.

But everyone else does when arrays are used. It was a blanket "stop suggesting sh!t beyond the noob's level" comment...

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

Ever hear of rounding?

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

Giving it some thought you should ignore the previous post

The more you backtrack like this (you've done it twice that I know of today) maybe you should give it some thought before posting... Maybe??? ;-)

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

No offense, but this statement makes you seem childish and bitter.

What I find interesting that rather than posting the statement

Ignore the above it would be an answer so it's evil and totally stupid of me to post

and making himself look... well... you know... he just didn't delete the explanation himself and not post it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
    while(iss){
    {
        string sub;
        iss >> sub;
        cout << sub << endl;
        a=sub.length();

        index=sub.find_first_not_of("aeuio");
        cout << "first consonant:"<< sub[index]<<endl;
        harf=sub[index];
        sub.insert ( a, harf ) ;
        sub.insert (a+1, "AY"); 
        sub.erase(index,1);
        cout << "new word:" << sub << endl;

    }

This section does not do what you want. Even if it works you get
"each" ==> "eahcay"

index=sub.find_first_not_of("aeuio"); What if index is zero?

The instructions "put the first consonant to the end" does not mean the fist consonant in the word. It means if the first letter is a consonant.
each becomes "eachway" (note -- add "way" not letter+"ay"
touch becomes "ouchtay"
Also note that "this" becomes "isthay" and "straight" becomes "aightstray". It's the first consonant sound(s), not the first consonant letter

You did good outputting the strings to see what is in them. Now output the integers to see why you are getting "subscript out of range."

Additionally, do you want to insert at the end? Or is there a better way without having to know the length?