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

I have no idea what you want. The answer as I understand the question is "don't call the function until you want it." But since that's obvious, that can't be what you're asking.

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

Do you mean that you don't want to have to press enter after each (one character) number is entered? If so, then yes it is possible. I'm sure I have seen this done a different way, but here is one way anyhow:

char num1, num2, num3, num4, num5;
    cout << "enter 5 numbers:";
    num1 = cin.get();
    num2 = cin.get();
    num3 = cin.get();
    num4 = cin.get();
    num5 = cin.get();
 
    cout<<endl<<num1<<endl<<num2<<endl<<num3<<endl<<num4<<endl<<num5<<"\nPretty cool huh!\n";

You'll still have to press enter after the 5 numbers are entered, and this doesn't have error checking, of course. BUT if you enter 54321 (enter) then you will have your desired output. You could also enter a 5-letter word if you wanted to, since cin.get() gets one character.

That doesn't enter 5 numbers. It enters 5 characters.

I'm more on Vernon's side. Simply enter the numbers as distinct numbers: Enter: 1 2 3 4 5

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

I want to convert binary file to ascii. how to do that in C

Depends completely on what you need. Be less vague.

And if you want to now in C, why not post in the C forum, not C++ forum.

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

What is the condition that causes TRUE? What == what? That goes in the 2nd part (condition) of the for() loop.

The condition does not have to be based on k, but if you are running from k=0,1,2... until val == 10 (something calculated in the loop), you can certainly use for (k=0; val != 10; k++) Example

for (k=0; val < 10; k++)
{
    val = k/2;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at each characters in ss.
Use a loop so i increases for 0 to #characters ins ss
If ss is not an integer, go to the next character
If ss is an integer, subtract '0' from the character (this changes '2' into 2) and store it as required. Another array would be useful.

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

if you make two for loops nested like above, for each value of x, it will iterate to all values of y and go to next iteration which will do the same until all values of x are finished

In other words, it will loop over all values of y for all values of x, so the inner loop y runs x times.

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

What does "int" mean?
What does "double" mean?
What does "cannot convert" mean?

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

Yes we can. Start by reading the Member Rules and the useful posts at the top of the forum.

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

Using different objects for input and output the above code is not working. Pls give suggestion ASAP.

The suggestion depends on what the code is supposed to do. Since you didn't tell us, what can we we suggest?

at least other than Never use gets() , for various reasons
1) see this
2) why use a bad C function when a good C++ command works better?

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

the dean and the administration above him are responsible for enforcing teh use of shitty compilers. I believe the highest eschelon of your national university system is receiving kickbacks... er, i mean "incentives" from Borland corporation to perpetuate their shittiness all over the Second World.

I kind of doubt that. If they are getting kickbacks, they'd be passing out at least Borland 2006, not Turbo 3.0.

I'm sure the crappy compilers are being used because that's what the instructor learned on and he's never bothered to keep up with the industry (he's in academia after all) and just keeps plodding along thinking Borland is still king of the compilers. They are just lazy SOBs.

jephthah commented: good point. +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No, it's a real shot (actually two) of that street.

As google (or whoever) goes around taking pictures for the street views, the cars and pedestrians move between shots. Sometimes not enough so you get that effect.

If you look at the LA link (if not active check around the Hollywood, CA area, on Sunset, Vine, Hollywood) when you look up, youl
'll see a present a bird left on the camera dome...

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

Doesn't you class have a textbook? The explanation should be in there in the section on pointers.

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

Go to the principal or dean and explain to him that your instructor is handing out assignments without teaching the material, and he's forcing you to use a compiler that is 20 years old. You cannot learn adequately from a 20 year old compiler nor an instructor that won't teach what's needed for an assignment.

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

Can you tell us how many days between Mar 23 and June 5 of this year?
Don't use the computer, just figure it out.

Now do it again, but write down each step as you do it, and post it here.

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

We're not here to teach. You need to learn the stuff and we'll help you put it together.

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

Then look them up. In your notes or in a tutorial.

Or better yet, find a better school that teaches with a book that you can use as a reference.

zendet commented: very unhelpful, and not polite to new users +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'll bet tomorrow you might have a good idea.... :icon_wink:

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

OP seems to have record being passed in as a char* . Shouldn't it pass in as struct PATIENT * record ?

Good point. I missed that :icon_redface: I assumed it was the struct and didn't look close..

jonsca commented: No worries WaltP, I've had like 15+ of those in a row +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know what an array is?

Do you know what a string is?

How about a string array?

I'm asking because without knowing what you know, all our help will be over your head.

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

Hurricane123 is a cheater. I recognize this code, it's our department chair's code and he/she knows it.

Hurricane123 is trying to cheat their way out of doing the assignment the RIGHT way, by getting the daniweb community to write it.

Thanks for the heads up. But if you read the help we've given, we caught him with his first post. We've been down this road many times over the past few years with people that want a free ride, so we catch on really fast.

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

You do know you can say s[0], s[1], s[n] to get the characters of a string, don't you?

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

You are passing record in as a pointer. Don't you need record->xxx for all your fields instead of record.xxx ?

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

:D When you post answers to questions here do people jump down your throat about using bad techniques, commands, formatting? :twisted:
that would be clue #1...:icon_mrgreen:

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

local shops typically don't build laptops :)

All the ones I know of that build desktops also build laptops. It's still the same process.

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

Don't you have a textbook? Doesn't talk about arrays and strings? Aren't there examples? If not, Google knows all.

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

Since I have no idea what a "bootstrapping bond interest rates" is nor how to calculate it, I would suggest letting the program tell you what's wrong.

Before and after key calculations, display values and check them to make sure they are as you expect.

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

Okay. But what if you want to use cin for your program, but then you want to pause the screen without using

system("pause");

?

I expect you'd use cin.get() ? Is it better to do that or use getchar? Or does it depend on the program?

Why use a C function when the equivalent C++ function is available?

Apparently you still have to clear the buffer (or get it to ignore whatever's in there) in order for cin.get() to actually pause the screen.

Naturally. If you input a single character, one character is input, no matter what language you are writing in. If you press the ENTER, it's goes into the buffer. You have to get rid of it to read the next character.

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

Start at the top.
1) Create something in the program that holds 10-20 words. Add a loop to print the words.
Compile and correct until it has no errors and displays what you've done correctly.

2) Add some code to choose a random word. Output the word. Compile and correct until it works.

3) continue...

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

Because when you remove static, it's a local variable that has 0 loaded when the function starts ( int i=0 )
Pass the counter value into and out of the function.

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

Every time you input shape, display it as a character and and integer. You will see immediately what's wrong.

Things to look at:
1) Let the program tell you what is wrong. Output values to be sure they are correct.
2) Format your code better. There is no reason to indent just to indent:

}
		ofstream outfile ("PJ657_output.txt");  // why indent this?
			if (!outfile)
				{  // why indent this?
					cout <<"Error: cannot open PJ657_output.txt";
					return 2;
				}
		infile >> shape;

		while (infile)
		{
			if (shape == 'T' || shape == 't')
			{
				infile >> shape >>base >> height;
					Area = .5 * base * height; // why indent this?
						outfile <<"The given triangle has an area of "<<Area; // why indent this?
			}

3) Don't use system("PAUSE")

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

I tried to offer a few additional or redesigned smileys, but they were rejected. I figured there should be a difference between ;) and :P since they mean totally different things. Then J could have used :P as intended and not be misunderstood. :icon_wink:

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

Going back to your original function, between runs you have to have a way to zero your counter. Using a static value, you can't zero i when the new run starts.

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

Where is reg_num declared?

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

How about

char dummy;
char firstWord[10];
sscanf(text,"%c%s",&dummy, firstWord);
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I might be using anything...but I am using Dev-C++ for now. I also have VS C++ 2008 Express, but haven't used it much yet.

In addition (if it hasn't been pointed out yet) Mixing cin with getchar() should not be done. Stick to one style.

Meh...

Whenever I don't feel like writing that whole system pause thing, I do this:

#define pause system("PAUSE");

so then its usage would be:

pause;

This is one of the worst suggestions I've ever seen... How does this eliminate using system("PAUSE") as everyone else is suggesting? :icon_rolleyes:

MyrtleTurtle commented: That's why I like sites like this. There is so much they don't teach in class. Thanks for the info. +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I don't see anywhere in the loop any one of the while() values is changed. And, of course, if any one of those values is !=0 the loop continues.

I'd guess the while() loop itself is the problem.

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

I love being ignored.

I'll try 1 more time...

So what's missing in your triangle?
What is necessary to get the *s in the right spot?

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

So don't start your loop with your first value :icon_rolleyes:

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

Not even going to try reading that badly formatted code. Do instructors really teach that indenting 30 characters is a good thing?

Try this information

I just happen to notice this, too.

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

So what's missing in your triangle?
What is necessary to get the *s in the right spot?

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

So what's wrong? The program description doesn't make sense, but the code has only 1 minor error -- the for statement is a little off.

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

if you convert 10 to 'ten' then try this
No declarations at all.
1. Create a form and add two textboxes; TextBox1 and TextBox2
2. Add a command button; CommandButton1
3. Copy the code below to the code window.
4. Run the program, enter the number in TextBox1 and click CommandButton1..

What are they going to learn turning in your program? And don't tell me "they use it for a pattern for their own code" -- you know that doesn't happen much. And even so, we help people write their own code, we don't give handouts. Handouts they can get from Google.

After 600+ posts you should know all this.

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

Hey Walt, bd asked how not can I... :)

Yep. Sorry. I read it too fast. Missed the how

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

I guess we'll just have to find a system that uses non-0 as a return and see if a return 0; actually returns 0 or the system specified SUCCESS. And if it's changed, is it during runtime or code added at compile time (which if you think about it is massaged at run time, eh?).

We may need Narue's help for a system suggestion.

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

Here is the corrected code.

Also you must include "stdlib.h" in your source

Hope this was helpful.

No it wasn't. You don't get the grade, therefore you don't write their code. And we are trying to help him and you just wasted all the time we put in -- if your code actually works.

And suggesting stdlib.h is
1) not C++
2) not necessary

So all in all, a worthless post.

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

IT doesn't enter second loop don't know why. Any suggestion?

Yep.
Split for(int k=0; k<getphraselength(); k++) into 2 statements. What call the function every time you go through the loop? Make it:

len = getphraselength();
for(int k=0; k<len; k++)

Now you can display len and see if the value lets the loop run.

In general, don't call functions in the parameters of the for if you can help it.

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

Thanks for the reply.
What still confused me is that:
In general, an array is indexed by 1, 2, 3,etc. And we can have sth like A[1], A[2],…
But here, the count array is indexed by A,B, C. Is that right?

Almost. It's indexed by 'A', 'B', 'C'. Small detail but very important.

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

I was in the middle of moving some discussion posts into their own thread from a help thread and got his nose bent because it wasn't pretty yet. The discussion was getting long and was unnecessary to the OP. J thinks I was doing it to make him look bad. You know how he is.

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

I didn't try to install. I just ran the compiler. Maybe I'm even more old school than you...

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

For that example, you'd subtract 941 and multiply by 100. But if it is an input from the user which you do not know, would you change the double to a string and then use something like strtol to find it?

How do you know it's 941?
How can you get the integer 941 (or whatever it is) from your double?