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

In this case, no. A switch statement relies on different case statement values and your if statements do not have different values.

One problem I see in your if structure is what if 5 of the values in fact match set. This will only find 1 and stop. This may be what you want, but I thought I'd point it out.

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

i need to know how to clear screen and also how to get the numeric keys without pressing enter.

Both of those questions are answered in your post. You might want to reread it and look up the things suggested.

And while you're at it. look this up, too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
char *string1[100000], *string2[100000];  // You just created 
                          // an arrayof 100000 POINTERs not a 
                          // string of 100000 characters

int a, b, c, count1[27], count2[27], m, no;

int main () {
    
    for (m=0; m<=26; m++){
        count1[m]=0;         // Now you set all the POINTERs to 0
        count2[m]=0;
        }
        
    gets(*string1);          // read in something into a buffer 
                             // pointed to by the address of 
                             // STRING1.  On other words, 
                             // somewhere in Never-Never Land
    gets(*string2);

What you want, as mitrmkar explains, is to create an array of chars, not and array of pointers. He also is correct -- 100000 is much too large. Unless you are planning on typing in a novel.

Also, see this about gets()

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

Gotcha! :)

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

Not bad, I didn't realize that function existed. I thought you had to write your own!

If the purpose of the program is to teach you how to calculate an average, you do need to write your own.

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

Try what you are sure of, and attempt what you can't. Then post what you tried and we can help you fix it if you have problems.

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

Or you can use an equation to get what you want. in your example you specify 3,5,7,9 so:

n = rand() % 4;   // get numbers 0,1,2,3
n *= 2;           // make them now 0,2,4,6
n += 3;           // offset them to 3,5,7,9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi,

I am using Borland C Compiler for preprocessing a source file.
I am using the following command for preprocessing....

C:\cpp32.exe -P- -o"outputfilename" "Sourcefilename"

According to my requirement i should get source file comments into preprocessed
file. The above command is not satisfying my requirement. I don't which options i should use to get this. Please help me in this regards. I have attached sample source file also.

Another request for psychic help. How can we give any recommendations if you don't give us any useful information?

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

I'm curious as to why? Can't a keystroke be added the same as a ^B or ^I?

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

A little more information, please. What are you trying to output? Do you have particular formatting requirements (spaces, decimal precision, etc.)?

Please show the code you have so far, and tell us what you are having trouble with, in a more specific manner. Then we will be able to give you appropriate help.

If you've been following his 142 posts you'd realize he never asks a coherent question the first 2 or 3 posts in a thread, expects us to read his mind about his problem, and rarely if ever posts code. He just doesn't understand yet how to ask a question.

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

the max limit i have set in the for loop was a "max purchase" assuming you use like debit card. If you were to buy gas with some sort of plastic, they set aside a certain amount of money ie. 75$.

I was just trying to figure out how someone could start and stop the loop when they felt so compelled.

You really can't. C++ is not designed to 'stop when a key is entered' which it sounds like you're asking about.

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

In other words, look at the chapter on Input and Output

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

What happened to the ICODE button in C/C++? Could you please add it back, and on the quick reply, too? It would be nice to have a keystroke for it, also. Pretty pleaseeee???
(batting my eyelashes coyly)

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

I have given this program only to develop your logic ,it is not a standard form .

And where in your original post did you explain that? So how is the person you're trying to help going to know your program is only a logic lesson? And with all the problems, how is he going to know what is good and what is bad since he's new to programming?

IOW, don't help people by showing bad code because it's confusing and does more harm than good. Show an algorithm rather than code if you can't post good stuff. For one, they can learn more from a good algorithm. And, secondly, they can't turn your work to get a good grade. They have to still write it themselves.

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

Thanks for the reply.
I managed to get the file printing to work, however i still cannot update the memory locations pointed to root1 and root2 with the two values of the quadratic root. Is there a specific way of writing an equation to update the memory locations?

What memory locations does rootone and roottwo point to? They look like simple variables to me. And simply assigning a value with the = sign updates the variable, and that you are doing. Therefore, I guess I have no idea what your question really is.

So, I suppose the question I have is "what part of the first half of my response did you not understand?"

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

when i say "readable" i meant for the average programmer. not for someone who can't grasp that "!" is the same as "== 0 "

perhaps we should

#define YES_INDEED_THE_STRINGS_ARE_EQUAL            0

?

That works for me.

Programming is not just being able to put variables and operations together. There's a logic that you need to follow to be good. The thing I'm pointing out is a good programmer will not use a boolean test for a non-boolean comparison. strcmp() is not a boolean function, therefore it's bad form to treat it as such.

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

I'm not sure how to combine the use of bubble sorting and c I/O functions. After opening the file, I don't know how to read the contents.

Do you have a book? If so, there's a chapter on I/O (input and output). Might want to read that. if you don't have a book, you need to get one.

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

Although correct, I have never seen such an operating system, but there could be one or more very obscure os's that have that quality.

Which is why you can ignore this advice. I've never seen (at least in the past 25 years) a system that a student uses that has a non-contiguous alphabet.

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

I m talking about all the programs i have made and I use Turbo C compiler...

I am appending the whole code...... Check it out...

No way. You didn't use CODE tags which are mentioned
1) In The Rules you read when you signed up
2) In the post aptly titled Read Me: Read This Before Posting
3) In the post about BBCode Tags
4) On the background of the input box you posted that unreadable code.

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

Ive sorted that problem but how can i read the persons name and write it to a txt file and then read the company name and write it? Also i need to output a " to a text file how do i do this?

Maybe by having the company name in the input file? And if all you are doing is copying the file, why do you need to output a "?

Maybe you need to explain what you are trying to do and not give us small pieces of the problem that don't make sense all by themselves.

Have you read Read Me: Read This Before Posting yet?

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

owh i get it but hwo about in million
can u make me some codes of that like this

Can't you write ANY code at all? Do we all need to do your homework for you?

This is lazyness, but i have nothing to do atm so....

"... so I'll write it for you so you can pass you class and not have to learn anything but how to beg for answers." Is this basically what you meant?

your really starting to sound like you want someone to do this for you with no effort...

Starting? I thought his second post showed this. And he confirmed it absolutely with

so what is the complete of that code...? and how about in roman numbers...? tnx

So far he has posted absolutely no code and has gotten at least 3 programs in response. C'mon guys, this is not a handout clinic here!

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

im a biginner level in Visual C++ version 6.0
"how can i Write the Program ”Minesweeper”.

You don't. That is not a program for a beginner. Start with something easy like craps or tic-tac-toe.

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

Change cin >> variable to cin.getline(variable) And use full words in English as the Rules specify. You did read them, didn't you?

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

i cant seem to figure out are how to accept a user input to start and stop the gas pumping loop and how to pause the loop at the start so that it appears to "zero out" before pumping gas.

Aren't you supposed to enter the amount of gas to be purchased?

i have the same type of program i am working on and got as far as you did...but for my program i need to use the rand function. the user only inputs the number of customers and then the program randomly generates the number of gallons and calculates price for each customer. The price per gallon of gas is constant. Anyone have info on rand and how to use it?

What does you book say about rand() ? Look in the index.

PS. I would apreciate it if no else tried to threadjack me...Thanks!

Yes. this is frowned upon here.

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

jephthah, "try to keep code basic and readable for the next guy, rather than using clever logical constructions" is very good advice. But then using if (!strcmp(progress,"YES") || !strcmp(progress,"NO")) is not easily understandable. It assumes you understand that strcmp() returns FALSE on equality, which is illogical. Better to use if ((strcmp(progress,"YES") == 0) || (strcmp(progress,"NO") == 0))

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

My problem is that i do not know how to update the memory locations

It sounds like your instructor wants you to use global variables for rootone and roottwo. Check with him to see if that's true.

to write into an output file without overwriting what is already there from the previous calculations.

Open the output file for append. Use "a" instead of "w"

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

Gee guys, are we rewriting the text book? :icon_wink:

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

It will Help you !

Why this is bad help:
1) No CODE tags
2) No formatting, code is very difficult to read. See this
3) #include<conio.h> -- not portable. Do not use.
4) void main() -- see this
5) clrscr(); -- only 1 compiler defines this function - do not use
6) getch(); -- not portable. Use standard C instead, like getchar() barbiegirl,
Please explain what you want in detail. Your explanation is lacking in data necessary to understand your problem. Did you read the post titled Read Me: Read This Before Posting?

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

The best place to put the calculation is after you've read the data used in the calculation.
The best place to output the answers is after you've done the calculations.

And you need to use CODE tags as described in The Rules you read when you signed up. Did you miss that paragraph?

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

Yes, a while loop would work, or better yet a do-while.

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

I find most ads insulting. Payback is h*ll :icon_wink:

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

system pause seems to be frowned upon anyway, but the best replacement (if you don't care about portability) could just be to use

#include <conio.h> // windows only, for getch
cout << "Press any key to continue."'
getch(); //waits until one key is pressed

A terrible suggestion. Why suggest a function that is not available in most compilers? Anything wrong with a simple getline() , which is defined in ALL compilers?

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

Please explain this line: scanf("%lf%*c", &y); It makes no sense with the format specifier you have.

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

So after you read a name, check the last character in the name and if it's a \n change it to \0.

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

Yes, again. Looks like you have it figured out.

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

First of all, use CODE tags as explained in the Community Rules you read when you joined.

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>

void main(int argc, char *argv[])    
                // argc=#of parameters  
                // argv=array of strings for each parameter
{
int status;
char *prog = argv[0];
                // first argv string is the program name
                // load prog with the pointer to that string
                
char *new_cmd = "/bin/echo";
                // the command to be executed by the O/S
                
char *cmd_args[] = {"echo", "hello", "world", NULL};
                // an array of strings containing the arguments 
                // to the /bin/echo command:
                //          bin/echo  echo hello world
                
char *cmd_env[] = {NULL};
                // there are no environment parameters needed
                
status = execve(new_cmd, cmd_args, cmd_env);
                // execute the ECHO command with the parameters
                
/*
* execve does not return unless there is an error.
*/

fprintf(stderr, "%s: ", prog);  // output the program name
perror("execve");               // output the error status from the call
exit(1);
}

Also, read this about formatting your code.

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

It's because you can't create a buffer using a variable as the size:

int buffer = 11;
	char name[buffer];

You need something like:

#include <string.h>
#include <stdio.h>
#include "input.c"

#define BUFFERSIZE  11

FILE *playerdata;

int main(void)
{
	char name[BUFFERSIZE];
	printf("Please Enter Your Name\n");
	printf("Maximum Length 10 characters\n");

And what if her name is Elizabethany? :)

midimatt commented: Thanks for making me realise the problem :) +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Don't try to do it all at once.

First, check for the negative sign. Make sure there is only one and it's first.
Then check for one decimal.
Last, check that there are only digits, decimal and negative signs in the input.

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

You learn by checking out how someone else coded theirs. Find a couple more
O/S's to look at and check for similarities and differences. Linux is also available as source.

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

When are you going to learn to explain what you want in understandable terms? "I want to call (3,1) then (3,13), then (3,34).........." means what? What does "call" mean?

"How to declare 3 is the first than 13 is second?" is also meaningless. The first what? The second what?

Give us a full explanation of what you are trying to accomplish.

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

As hockeyplayer suggests, read a line at a time. Then use .find() to locate the @ if present. If you find it, set up 2 loops:
Loop 1 tests each character before the @ to find the first character that is illegal in an email address (such as the ']')
Loop 2 does the same for each character after the @

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

We need to see code in order to figure out what's happening. Isolate the problem by creating a small version of the program that exhibits the same problem.

Copy your program and start removing sections of code you know does not cause the problem -- piece by piece. When you get it to a few lines, one of two things will happen:
1) you'll see the problem
2) the code's small enough to post

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

When you read the Community Rules, what part of this rule did you not understand?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Get start NODE
While NODE exists
    do something
    NODE = NODE->next
end-loop

It's quite simple.

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

He was also in "Cold Turkey", which sorry to say was a real turkey.

Although "Drop Out Father" was good.

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

I've loved the Dick Van Dyke Show since it started. And I think he's great is most things I've seen him in! But until you mentioned it, I never made this connection! :icon_eek:

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

Thanks a bunch WaltP, although it isn't exactly what I wanted, ...

Yes it was. You already found the first half of what you needed, I supplied the rest of the puzzle. :icon_wink:

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

You sure do like recursion, don't you? Can't you just use a standard loop?

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

abhikkumarbasu, it would really help if you'd read the threads you are responding in. He very definitely said he's using DevC++.

And I've seen other posts that you've offered the exact same advice as the post immediately before you -- and hours earlier.

We appreciate you desire to help and fully welcome it. Just try to be a little more observant so you can help people with the best advice.

add getch()

AD?!?! Really? Don't you mean getchar() ? :icon_wink:

Ancient Dragon commented: good catch :) +24
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You're looking for kbhit() , the fraterna; twin brother to getch()