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

First let me tell you what my program is doing. its basically a shopping list program. Whereby the user will input the values and it is then inserted into a text file. There will be 3 inputs (Item Description,Unit Price,Quantity Purchased) and is stored into the text file as (Shoes:$200:2)...

getline reads a line from the file. What do you have in one line of the file? That's a big clue as to why the line in the file is displayed as the item description.

I know i need to use the getline() and use a delimiter but i dont know how to put it in my code.

Try Googling for getline or reading your book about it.

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

Got It. "The Ball is In" by Puretronic

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

can modify my program pls...

Why?

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

A suggestion if I may...
Create a function that takes
1) Package
2) Usage
and returns Cost

Then you can call the function at the top and display the usage cost.

For part 2, call the function twice more with the other two Package values and you can subtract the costs from the Cost above to check for savings.

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

My psychic powers aren't working. I have no idea what you tried any of the three times so have no suggestions other than think through the problem on paper and don't try to code anything until you understand the problem.

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

well, i tweaked it, an added an option for the user to enter a number and depending on the number, a certain variation of the array will be shown....but i havsin some difficulties....could anyone help me as to where i went wrong?

The first thing you did wrong is expect us to read your mind. "i havsin some difficulties" doesn't tell us anything. You need to tell is what the problem is.

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

Thanks ddanbe. The translation is helpful.

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

@imkj:the code is the same thats above... both the links(4shared & c.happycodings.com) have got errors(sadly,too many)...

Then you should happily contact the author and ask them to rewrite it for you.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
#include<iostream.h>
using namespace std;
int main()
{
cout<<"Welcome to microchip Computer Education";
return 0;
}

the .h after iostream doesn't matter

WRONG!!! It matters big time! Only the headers without the .h require the namespace commands/indicators. The .h headers are old and should not be used at all in today's C++ compilers.

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

i needed to dynamically allocate memory space for filename.

No you didn't. Dynamically allocating memory is only necessary in rare cases. For a short filename, it is not necessary.

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

Output your variables at key points in your code.

What's the value of argv[1]? Is it correct?
After diddling with filename, what's it's value? Is it correct?
Did the open on filename work?

There is nothing anywhere in computing called a Degbug. Copy and paste the exact error, and the code, into one post. And explain exactly how you got the error.

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

Also, never copy stuff to argv[]. That's a system-defined array, not for user storage. Consider it an input-only value.

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

I know it has to do with the way I an assigning filename and argv. argv is a pointer...

Yes it is.

... and filnaame is an array. I might be using the wrong type for the filename

No it's not. char *filename = new char [100]; defines a pointer that gets the address of a character array created from the heap. Why are you doing this? Why not just char filename[100]; :icon_question:

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

Again with "having error". Like it gives the wrong answer? It doesn't compile? It burns the coffee? It destroys Tokyo? Some idea of what "error" means would be helpful.

And now that you've fixed it with the IF, please fix your formatting.

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

I know the definition I just dont know what to do to initialize the variable . I have tried every thing

Obviously not. What's the value of grade when you output it? Point to the line that loads the value you claim it has.

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

Try entering an invalid file name.

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

That depends on what arun means.

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

What does the word initialize mean?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
do
   {
	  in1.open(argv[1], ios::binary);
           if (!in1)
           cout << "That is not a valid file.  Try again!\n";

   } while (!in1);

interesting loop. Try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, ... You might want to rethink that.

After running the program it works but I keep getting an error message about my variable "filename".

Well, then something is wrong. Give us the info we need to understand the what "an error message" might mean. I can think of 5-10 things.

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

As to human evolution, it's impossible to predict and there are many contradictory ideas.
I myself believe it's either stagnant or reversing,...

So we're becoming apes again? In some cases that's certainly looks true :icon_razz:

... as there's no longer any competition based on genetics going on to select the best traits for the next generation and in modern countries it's those who're least productive and least important for the survival of the species who breed the fastest, the mentally and physically deficient, the lazy, the incompetent who can't or won't hold a job and actually make something of their lives.

Check out the movie Idiocracy -- it shows a possible result... :icon_twisted:

frogboy77 commented: funny idea poor film +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then, after you do what Adak suggested, on a piece of paper draw 2 empty matrices labeled arr and barr. Label the left sides and tops based on the indices used in the program posted. Now follow the program line by line, recording values of all the variables.

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

If you are going to post a question, and you get responses, read the damn posts! You have been told how to fix this. By me and the compiler.

If they are teaching you to use void main() and iostream.h you can either
1) Find a new instructor that will teach current coding practices
2) Understand that you are learning how to program 1980's code and your knowledge of programming will be severely handicapped when done.

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

Updating your Mingw and [getting] rid of what came with your IDE will not help. The problems will still occur with an updated compiler.

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

Read up on the semi-colon. You have no idea yet how/when/where to use them. Your book is the best place to learn this simple stuff.

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

for a text box there is a property called autocompleteSoruce

Not in my version of VB6

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

No wonder you're confused.

I am using Dev-C++ and when I am trying to compile a program in it, it is showing many errors. All the settings seems to be right. Can I compile a program including header files like conio.h and iostream.h and using namespace std in Dev-C++?

You are using 3 different eras of programming

  • 1980's - conio.h from non-Standard C programming. Suggestion - remove it and all functions used from it.
  • Pre-standard C++ using iostream.h -- again old and substandard. Upgrade to iostream, no extension.
  • namespace std for use with today's standard headers with no extension.

Decide what era you want to compile and fix the code to that standard.

confused_one commented: thank you sir for your suggestion +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Which goes to show that the compiler can do a lot more optimizations than you can. Trust your compiler, don't waste your time doing micro-optimizations like this, unless you have solid evidence that you need to do so.

Could the reason he's wasting his time is to learn to program, not outdo the compiler? There are many reasons to reprogram a built-in function -- first of which is to learn, not replace. Even in K&R they wasted their time by programming built in functions -- in multiple ways.

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

Set up another variable (power) set to 1

Use a loop.
As you go thru the loop
1) Mult power by num1 -- n^i
2) Divide by loop index
3) Add/Subtract that value from a total

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

I ran across this song and would like to know who it is, what it is, and what language is it? It sounds German-like but not quite. Is it about football? (that's soccer for you NorteAmerican folks :icon_wink:)

Thanks.

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

Oh really??? Where are they then? The only links to code snippets any more are from within the member's profile. But I don't want to search 50,000+ member's profiles just to find tutorials and/or code snippets.

908,364 Members profiles :icon_wink:

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

If IDE A has a tab spacing length of 2 and IDE B has a tab spacing of 4, as long as you are consistent with the tabs, and as long as its only used to indent the code, that alone should be fine. Mixing tabs and spaces is the primary issue.

And when posting on a forum, all bets are off. TABs rarely line up the way you want and given proper (and deep) indentation the code is difficult to read. By converting TABs to a set number of spaces in your IDE, your code will always be readable.

Consider with SPACEs

int main()
{
    int i, j, k;
    printf("Listing: ");
    for (i=1; i< 10; i++)
    {
        for (j=1; j< 10; j++)
        {
            for (k=1; k< 10; k++)
            {
                printf("%d:%d:%d ", i,j,k);
            }
        }
    }
    return 0;
}

vs with TABs

int main()
{
	int i, j, k;
	printf("Listing: ");
	for (i=1; i< 10; i++)
	{
		for (j=1; j< 10; j++)
		{
			for (k=1; k< 10; k++)
			{
				printf("%d:%d:%d ", i,j,k);
			}
		}
	}
	return 0;
}

The second one doesn't look like my editor, and is harder to read.

And if just posting a portion of the code 8 levels deep:

for (k=1; k< 10; k++)
                                    {             
                                        printf("%d:%d:%d ", i,j,k);
                                    }

vs

for (k=1; k< 10; k++)
								{			 
									printf("%d:%d:%d ", i,j,k);
								}

So TABs are evil. So there. :icon_razz:

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

On that kind of IDE, your better off using spaces exclusively or tabs exclusively.

Actually you're (note the spelling) better off using SPACEs. They are always consistent. TABs are not

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

Use a combo box. That has a dropdown already whereas a textbox does not.


Don't you ever get tired of typing "Thank you in advance and i am hoping for your positive response... "? It's really getting old -- over a year and a half old... And unnecessary. :icon_rolleyes:

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

combobox.Keypress

You make your own 'clipboard'

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

The only thing "automatic" about windows is that it is pre-installed on most PCs, the rest is just a succession of frustrating hassle and time wasted to get anything done with it.

Not most people's experience...

...while on windows you need to search on the web, download a few candidates, launch the install, enter a bunch of irrelevant configurations, press "next" a thousand times, and while you're doing that, you're not doing anything else (or even worse, you have to make a trip to a computer store and buy the software and bring it home).

This sounds just like those commercials for pasta cookers and the like. "No one can cook, strain, and serve spaghetti without dropping most of it down the drain, burning themselves, and serving what's left in a goopy gloppy sticky mess! Use the Linux pasta maker!"

In linux, any software is just one command-line away,

Really!?!? Kool. Sorry, I didn't realize every single software package available for Linux is on the distribution media! You never need to search the web for anything, ever! No downloading ever. Everything you could ever want is right there, in the distro package. By the way, how do you even get Linux? It must magically appear on your computer simply by thinking it into existence, eh?

You sound like the Anthony Sullivan of computers, proving which is better by half-truths and misinformation. Sorry, don't buy it.

I am not a Linux hater in any way, shape, or …

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

>>>>...while the simplest install of Code::Blocks with an up to date gcc is multi-step and somewhat manual.
>>Sounds like a Linux-user's dream software..

Is badmouthing Linux really warranted? You should know that one of Linux's main advantage is the fact that package management systems make the installation processes for any software super simple and automatic. Installing software in Windows is such a hassle compared to Linux.

Who's badmouthing Linux? The O/S is know to be a geek's O/S. You need to know more about the system to get things running. It's like using a car with a manual transmission -- more control, more knowledge needed. Not a bad thing.

Windows is the automatic transmission of the O/S world -- put it in drive and step on the gas. Any lameoid can use it.

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

Just as I surmised:

I suspect a bunch of parrots just jumped on the bandwagon. Aside from the debugger interface, of which I wasn't a fan, I had no serious issues with Dev-C++ (either stable or beta).

IOW:
It's not the bleeding edge so it's bad. It's not under development so it's bad.
rather than
It works well. It's a little outdated, but for a beginner it's a perfectly acceptable compiler/IDE pair for learning the language.

Bottom line:

Is Dev-C++ bad? No. Are there better options? Hell yes.

Of course there are better compilers. There always are and always will be. But is Dev-C badmouthing warranted? It doesn't seem so.

I still want to hear from someone that can explain how it's buggy... pseudorandom21? Care to backup your statement?


...while the simplest install of Code::Blocks with an up to date gcc is multi-step and somewhat manual.

Sounds like a Linux-user's dream software... :icon_wink:

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

Lol I hate to say it but Dev-C++ is a poor choice also, it's buggy and no longer supported as far as I know.

Really? How So?

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

For years when people post that they are using Turbo-C/C++ they always get a heated response saying basically "why are you using that piece of sh*t? Use Dev-C++ instead."

Dev-C++ was being recommended because it's newer, it followed the standard better, it's free, etc. A couple years ago, though, it stopped being supported. Now, just because it's not being supported, it's now terrible? It even elicits responses like

Lol I hate to say it but Dev-C++ is a poor choice also, it's buggy and no longer supported as far as I know.

Buggy? If it was so buggy, why was it being recommended for so many years? What kind of bugs does it have? And why are programmers dissing it all of a sudden? When it became unsupported did it also break?

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

You are doing the right thing already. Anything else is just more complicated, time consuming, and obfuscated.

Just because you read a line, doesn't mean you have to scan the characters.

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

I'm wondering how to remove the stuff at the end of the console, where it says the execution time, press any key to continue, and what the process returned. I am using Codeblocks.

Run the program directly from the console. It's CodeBlocks itself that's outputting that stuff.

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

unless your planning on using this in a business there is really no reason you can't post full code.

Sure there is.
1) It's too long
2) Cheating/lazy classmates.

if not please try to elaborate better if your not use to speaking english use google translations to translate your native language to english :P

Have you actually see those translations? They're horrid! :icon_eek: And use punctuation yourself, please.

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

cant tell your code doesnt seem to read the file properly maybe you should print the data to the screen after reading it that way you can actually follow what the code is reading it also helps to use punctuation so we dont have to struggle to understand your question i hope this answer helps you understand both problems

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

But am helpless without codes i said. And am ready to post my codes, but the problem is that its incomplete and i created now so far that i can understand.... I just waited for the code that suits my requirements.

What this really tells us is "I'm not going to post my code, I need you to write the code for me." Read the Rules.

I thought that the members would be totally confused by my dirty coding.

So how do you clean dirty code? By not asking how and letting someone else write it...

Since I need to create some text files, I tried my codes. But they only encountered in error.

How do you clean up an error? Post the code and EXPLAIN what it does and also EXPLAIN the error.

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

You didn't call the function in the DLL correctly would be my guess.

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

What did you expect to be displayed? Where did you put that value into TotalCS? Did I miss it?

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

Thanks for all your replies. But can anyone think that these are the reply to my question? Am i helpless regarding this?

Yes, absolutely.

Let's recap. You asked a question giving an example:

...say an incorrect program..:

for(int i=0;i<=12;i++)
{
     ifstream comp("%i.txt");
     comp.close;
}

i know the code is incorrect. But the text document to be created as such 1.txt,2.txt,...12.txt.

OK, that tells us what you are trying to do. Answer was:

You can use a stringstream for this. Try something like...

You said it didn't work. Why? Because:

@ravenous Yep, am using turbo c++ 3.0 version. I know it tat its too old to do. But i hav no more way since i feel difficult to use visual studio. Am not more updated. If i get any proper tutorial i do improve.

you know it's too old. Visual Studio is too hard. If you get instruction you will improve. So you were told:

I heard that Code::Blocks is a good free compiler.

Personally, i'm enjoying using Qt Creator at the moment. It's free, simple and nice to work in. There are versions for Windows, Linux and mac.

There -- two new compilers. Did you try them? Were they too hard? Must be:

Any one pls answer my question for creating multiple text files pls...!

Am using turbo c++ version 3.0 in windows xp platform..

If you want to improve, get a new compiler....

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

replace line 34 with line 26

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

sir i have a problem in the c program.

switch(ch)
{
case 1: t=a+b;break;
case 2: t=a-b;break;
case 3: t=a*b;break;
case 4: t=a/b;break;
default:printf("invalid no:");
}

when i execute the program and the any choice the comipler skip to the default statement. is it any problem in the syntax. sir please solve my problem.

Then the value of ch is not 1, 2, 3, nor 4. There's nothing wrong with the code other than being poorly formatted.