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

Try printing out a copy of your program, grab some paper and a pencil. Sit down at a desk or a table.

Start at the first executable statement in main() and follow the program statement by statement. Write down the values of all variables. Write down everything that is displayed. IOW, you be the computer and desk-check your program.

This is a fundamental part of programming -- checking your work.

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

IMO, simply reporting it is best.
If it's a seasoned user, go ahead and blast him with rep, then report it.

Don't reply, though. If we decide it should be moved, we need to deal with both posts. If we decide it should be deleted, we need to delete both posts. And in either case, you probably don't want a PM saying something happened to your post via collateral damage.

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

... But the thing is that bumping threads is not against the rule and hence asking someone to "not" bump a thread in my capacity as a moderator/super-mod would be wrong IMO.

I disagree. Even though it's not illegal to play at the edge of a deep pit, 'officials' (parents/teachers/police/...) will ask (tell) you not to.

There are many unwritten rules/guidelines, and not bumping a thread is one of them. A mod, IMO, should ask others not to break even these unwritten rules. The perpetrator just can't be forced to comply. The police do it all the time. As do others in 'power'. That's where rep can come in, as a hand-slap.

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

Lucky stiff... :X

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

If all those spaces are consistently in the place you show them, use the >> operator when reading the file. It will read everything between the spaces, one set at a time.

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

Take a look for what? Just to read it?

If you're looking for help, try explaining what help you need.

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

Thread bumping rule isn't an absolute. It's just that 99.99% of the times the bump is irrelevant/off-topic/spam/homework kid, making us a bit strict/wary when it comes to bumping threads. If you feel you absolutely must reply and add a new view point to the discussion in consideration, go ahead.

Although my suggestion was to see all the other suggestions so you won't repeat what's already been thought of. Anything new can be posted here. I would question the need to revive the older threads.

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

This is a programming forum, not an investment forum. What you are asking is information on investments. Best to check elsewhere and come back with your attempt at programming the algorithm(s) you find.

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

Set a maximum of 100 people. I'm sure that's more than anyone simply testing your program will enter, and if they try to enter 101 a simple error message will prevent it.

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

I'm just worried that in the long run if my programming skills can affect me alot when I become an software engineer.

If you can't cook, would that affect you as a chef?
If you can't handle driving large vehicles, would that affect you as a bus driver?
If you can barely add and multiply, would that affect you as a math teacher?

This sounds like a question that answers itself. And one you need not be concerned with -- unless you don't plan on learning good programming skills. You just need to study, and practice. Get good.

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

fgets() reads up to n-1 characters or \n, whichever comes first.
Write out what was read.
Read again to get the next batch of characters.
If the first fgets() reads 1/2 a line, the next fgets() reads the rest.

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

OK, here's a complete description:

File contains:

Tom Babidal<\n>
93 94 99<\n>
Billy Marks<\n>
13 98 56<\n>
etc<\n>
etc<\n>

your Code:

getline(infile, student1); 
	infile >> score1 >> score2 >> score3;

Execute getline() -- file now contains:

93 94 99<\n>
Billy Marks<\n>
13 98 56<\n>
etc<\n>
etc<\n>

Execute infile -- file now contains:

<\n>
Billy Marks<\n>
13 98 56<\n>
etc<\n>
etc<\n>

Note that I said "You aren't reading the NewLine after the numbers. When reading numbers, the system stops reading when the number is finished." Well, there it is -- line 1.
Execute getline() once more, reads to the next NewLine -- file now contains:

Billy Marks<\n>
13 98 56<\n>
etc<\n>
etc<\n>

What's the infile going to read?

Maybe you could have asked a question rather than making a cryptic comment...

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

Maybe more information would help. Like why you need the \n when getline() clearly reads the entire line.

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

Jeez. Try This.

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

Yes

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

Try This

I fear for the future of the world... Isaac Asimov's story Profession is definitely in the making.

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

Can't you come up with something better? Sounds like Miss America... :icon_rolleyes:

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

I don't know what that means in relation to my comment.

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

I have the searching part done, but my bubble sort isn't working right. It seems right in my head, so I'm not sure what's wrong.

Then get it out of your head and on your desk with pencil and paper. The mind is a very bad analog for the computer.

When programming, the last thing you do is type the code in. Before that you need to sit at a desk and write down your steps, eventually convert that to code, and execute that code line by line on paper to iron out the details and problems you forgot about.

Once it looks good on paper, that's the time to type the program in.


You'll thank me later... :icon_wink:

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

randNum = (rand() % range) + firstNum;

range is the total number you want to generate
firstnum is the beginning number of that range

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

Tell you what -- do a search for this very topic and read the scores of previous suggestions that have been proposed. And their responses. Then you can curtail the need to come up with the same ideas that have been mentioned over the past few years yet again and go right to things that have yet to be thought of. :icon_wink:

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

You aren't reading the NewLine after the numbers. When reading numbers, the system stops reading when the number is finished.

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

Compile the code and time them.

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

Just reverse the write. Do a read instead.

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

We don't help people cheat. Sorry. You need to do some research to do your assignment.

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

Isn't the End-Of-Line also considered the end of a word? And it's not a SPACE.

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

As I said,

There is no decimal with integers.

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

Well if you really want to be French then i wont stop you, but it is not a trivial decision.

I feel a little green today... Think I'm going to croak... I'm beginning to like Jerry Lewis!

Edinburgh is not ENGLAND.

Well, I did say maybe... :icon_wink:
I know it's in Texas. Or are you talking about this one or this one? :icon_twisted:

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

All those values are integers. 1/36 = 0. 2/36 = 0. There is no decimal with integers.

So make the values real: 1.0/36.0 = some floating point value

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

fgets()

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

Set one value before you start testing.
Only reset the value when the condition you need to test for is met.

In this case, assume it's prime, set value to IsPrime.
During the test phase, any other factor sets the value to IsNotPrime.
At the end, if value is IsPrime, no other factors have been found.

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

Since we don't know the format of the files(s) what can we tell you?

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

And what do we get for doing your homework for you? Better question, what do you get besides an A on the assignment and no knowledge whatsoever.

Oh what the heck:

#include <stdio.h>
#include <math.h>

int main()
{
char tmpvals[]= { 0x54,0x68,0x69,0x73,0x20,0x70,0x72,0x6F,0x67,0x72,0x61,0x6D,
                  0x20,0x77,0x61,0x73,0x20,0x6E,0x6F,0x74,0x20,0x77,0x72,0x69,
                  0x74,0x74,0x65,0x6E,0x20,0x62,0x79,0x20,0x74,0x68,0x65,0x20,
                  0x73,0x74,0x75,0x64,0x65,0x6E,0x74,0x2E,0x20,0x53,0x2F,0x48,
                  0x65,0x20,0x61,0x73,0x6B,0x65,0x64,0x20,0x66,0x6F,0x72,0x20,
                  0x74,0x68,0x65,0x20,0x70,0x72,0x6F,0x67,0x72,0x61,0x6D,0x20,
                  0x74,0x6F,0x20,0x62,0x65,0x20,0x77,0x72,0x69,0x74,0x74,0x65,
                  0x6E,0x20,0x62,0x65,0x63,0x61,0x75,0x73,0x65,0x20,0x68,0x65,
                  0x20,0x77,0x61,0x73,0x20,0x74,0x6F,0x6F,0x20,0x6C,0x61,0x7A,
                  0x79,0x20,0x74,0x6F,0x20,0x64,0x6F,0x20,0x69,0x74,0x20,0x68,
                  0x69,0x6D,0x73,0x65,0x6C,0x66,0x2E,0x20,0x57,0x6F,0x6E,0x64,
                  0x65,0x72,0x20,0x69,0x66,0x20,0x68,0x65,0x20,0x73,0x68,0x6F,
                  0x75,0x6C,0x64,0x20,0x70,0x61,0x73,0x73,0x3F,0x0D,0x0A
                };
    double e;
    double ex;
    double x;
    int    n;
    double nf;
    int    qry;
    float  fex;
    
    printf("Enter X: ");
    fflush(stdout);
    scanf("%lf", &x);
    
    
    
    ex= exp(x);
    e  = 1.0l;
    nf = 1.0l;
    n  = 0;
    while ((e+0.000001l) < ex)
    {
        n++;     
        qry = tmpvals[n] * e;
        nf *= n;    
        e += (pow(x, (double)n) / nf);
        fex = nf + tmpvals[n] / ((e*6) / ((3 * e) * qry));
        qry -= fex;   
    }
    printf(" %13.6lf calculated in %2d iterations \n", e, n);
    printf(" %13.6lf = exp(%lf) \n", ex, x);

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

[boilerplate_help_info]

Posting 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

[boilerplate_help_info]

Posting 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

What's a nod?
What's an edge?
What's a weight?
What the **** are you asking?

Treat us as if we aren't in your class and didn't hear the instructions...

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

And it's tuppence by the way:)

Maybe in England. Across the puddle it's 2-cents. Closest we get to tuppence is Tupperware. :icon_twisted:

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

See #1, #3, #4, #10, #12:

[boilerplate_help_info]

Posting 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 …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

[boilerplate_help_info]

Posting 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

Can any one help me by giving me the c++ program to split an 1d integer array into parts with structure.

[boilerplate_help_info]

Posting 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 …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

[boilerplate_help_info]

Posting 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 …
DeanMSands3 commented: It's not hard to get the code into proper formatting. -1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Which is more important, the car or the gas?

What good is your data structure without knowing how to manipulate them via a program? And there's so many programs that don't require data structures.

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

Now you missed #1, #4, #5, and #7.

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

The following code using long long works up to 20!. But again, i'm trying to find out why the vegaseat program stops working for some (a few) particular numbers. Has anyone else tried it ?

"...for some (a few) particular numbers?" Which particular numbers? If 12, we already explained that.

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

hmmmm....i tried a simple code with unsigned long and it worked until 12!

What's the maximum value an unsigned long can hold?
What's the actual result at 12?

cn v sumhow ... bt any easy diff way possible?

And what does this mean? Is it Swahili? Reread the member rules about posting in English.

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

I made the change as follow and works !

1) Who are you?
2) Why are you hijacking kyky365's thread?
3) Why are you not using code tags?
4) Why are you fixing kyky365's program so he can cheat?

We don't do that here...

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

'CE' is not a character therefor you can't use putc() Fix your switch to output a 'C' then 'E' in case-Z and output the character if not case-Z (default).

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

Yeah... but just using the code i gave above is a substitute for all of it..
Isupper resides in the standard library with the same procedure u mentioned here.. Why write the whole code, when there already exists a direct function for it ??

Yeah... and by just using the built in functions, what do you learn? How to use a built in function. What if your next language doesn't have that built in function? You can't program the task...

And

Since we appear to be giving away code these days

thread closed...

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

Problem #1: for([B]counter>0[/B]; counter<=4; counter++) -- first field is wrong.
I also question the interpretation that the 4 numbers must be distinct. I've never seen that requirement. But you need to follow your interpretation of the problem.

And this loop:

for(counter2=1; counter2<=1; counter2++){

		cout << "Round "<< roundN <<":"<<endl;
		roundN++;
	
		cout << "Enter Guess: ";
		cin >> input[0];
		cin >> input[1];
		cin >> input[2];
		cin >> input[3];
		
	if (input[0] == input[1] || input[0] == input[2] || input[0] == input[3] ||  
		input[1] == input[2] || input[1] == input[3] || input[2] == input[3])
	{              // what is the purpose of this if? I don't think it's necessary
	counter2 = 0;  // changing the loop counter is a very bad practice.
	continue;
	}
	else if (input[0] > 6 || input[0] < 1 || input[1] > 6 || input[1] < 1 || input[2] > 6 || input[2] < 1 || input[3] > 6 || input[3] < 1 )
	{
	counter2 = 0;	
    continue;
	}
	else
	break;

	}

The IFs are too complex and prone to problems.

As for the rest of the program, you are making it hard on yourself. You're counting values but not keeping track of what you need to keep track of. And you're testing the same thing over and over and over...

You need a copy of the answer array and another array for the result information which starts with all SPACEs or DOTs.
Create the first loop to test each input with each …

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

Who said //?