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

If the number must be exactly 5 digits, you'd be better off reading the number as a string and passing it into your function. By reading an int, you have the possibility of an error on the read if they type in a non-digit character. Reading a string removes that possibility.

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

Is this a joke?

Not only do you
1) resurrect and hijack an old thread
2) not use CODE Tags
3) post over 2000 lines of bad code
4) use a compiler and functions that haven't been used in 20 years

you also expect us to read it, understand what you're doing, and find out not only what the problem is but where. Heck, you can't even be bothered to tell us what the error is!

There might be someone willing to take this on, but most of us won't touch it.

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

Dev C is a C++ compiler. But, like most compilers, it can compile strict C programs as well.

And yes, given the right knowledge, you will be able to write the program you want.

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

Stop trying to fix his code! It's correct.

The problem is your terminology. You said

From that point, I go to the command line and after making sure I'm in the correct directory, i type "gcc dumb.c -o dumb" (no quotations obviously) and that's how i run the program.

That command only runs the compiler, not the program. You don't have a program yet.

Once compiled (and linked for those here who are anal about it) you still have to run the program. See the last part of anirudh33's post.


Also,

I know the program is working (sorta) because it doesn't give me any error message.

That's no guarantee it's working. It only means it compiled. Your syntax is all correct. But the program can still be wrong.

#include <stdio.h>
int main()
{
    int v;
    v = 2+3*5;
    printf("2+3 multiplied by 5 = %d\n", v);
    return 0;
}

This code works using your definition (no compile errors) but it's still wrong.
Why? :icon_wink:

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

A quick inspection of the code reveals that your not resetting the variable judgeCounter back to zero.

A note on code indentation...Please use it.

Yes, but don't use gerard's formatting. Indent 4 spaces, not a full TAB. TABs make the code hard to read.

Your IDE can be set to convert the TAB to 4 spaces so the code looks good no matter where you post it.

IOW, TABs are evil. SPACEs are wonderful. :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
while (select < 'A' || select > 'E')

Single quotes denote the character

i dont want the program to accept alphabets only numbers

You could look at my suggestion and maybe convert it into something you can use.

That's the idea behind programming. Take something similar and make it fit your situation.

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

Output d as a hex value, or use a decimal-hex calculator to check the answer.

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

Yes

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

feel free to edit or modify the code, its been a long time since I have played around with this code :)

Then you should have played with it before posting. goto and gets() are extremely poor techniques in coding. And for a professional? At M$? No wonder updates are needed continuously...

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

strings are collection of characters that you enclose it with double quotes.
eg:

char a[5]="world";

a[0] will have w
a[1] will have o
a[2] will have r
a[3] will have l
a[4] will have d.

Would you care to correct your description and not blow past your array boundaries?
And add the required information on \0?

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

An INI file is just a file that you define. It's a text file containing the data you want to write to it. It's not a special file, it just has a different extension -- .INI

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

Change your IDE/Editor to convert TABs to SPACEs. That will solve the problem...

jimJohnson commented: Great helper +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please send me a copy of the book by the fastest route possible. Then I can look at the problem, laugh at how simple it is, then wonder if someone else helped you cheat while I waited.

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

Open the .txt file for input
Open the .html file for output
Output the header
Read the .txt file
Write it to the output file
Close both

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

I do apologise if I am not using the CODE and the ICODE correctly.

This is a new one. Apologizing for not using something correctly that wasn't even attempted. Use Advance Editor would have told you immediately.

kvprajapati commented: Ha! ha.. HaPpY nEw YeAr sir :) +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Other than using the non-Standard scanf_s() I don't really see a problem. Try displaying t[jcs] after the input to make sure it was input correctly.

More info is probably needed.

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

Get the line then start testing. Don't get it in the IF statement.

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

so now im trying to read integers from input untill input is eof or blank line(line was left empty and enter was hit) ... ive found some codes(getline ) but it only applies for char type ! and i dont want to go through the whole conversion thing(but if theres a simple one ill consider it) !

Why do you want to do it the hard way and not the easy way?

Read the line.
Test if it's blank.
If not, test if it's digits (this is simple).
If so, convert to binary (also simple, one statement).

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

Start at the beginning of the string and look at each character.
Every time you find a ( remember it's position in the string.
When you find a ), evaluate the equation from the last ( to the just found )
Remove that equation replacing it with the answer just found.
Continue...

astala27 commented: Nice, you just express the algorithm +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

hi! iam a newbie how can i get the 10th, 100th, 1000th place for example: the interger is 1235, the ones place is 5, the tenth place is 3, the hundreds place is 2, and the thousands place is 1, please help me

Of course you're a newbie. Only newbies hijack other people's posts for their own questions. And then don't bother to try to answer the question themselves but ask here for free code. Of course, they also don't bother reading the other posts in the thread that already answer their question.

Jason Giggs commented: Nice One Walt +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

That depends on the compiler you are using. Would I be correct in assuming it's an old Borland compiler? 3.0 perhaps?

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

Hey people, this is a beginner learning how to use the C++ language. He is not a math major trying to analyze and implement the absolute best randomly distributed matrix possible. I gave a new programmer's algorithm, one that will suffice for homework, not a mathematically perfect distribution. That is above the needs for a beginning programming class.

Note, the first post states

Hello.I'm a begginer in C++.

It does not say

I am in an advanced mathematical theory course.

Help posters at the appropriate level, please. Higher math is unnecessary.

kvprajapati commented: True! +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

:icon_rolleyes: Oh ghod! :icon_rolleyes:

loop r from 0 to rowmax-1
  loop c from 0 to colmax-1
    row = random (0 - rowmax-1)
    col = random (0 - colmax-1)
    swap array(r,c) and array(row,col)
  endloop
endloop
VernonDozier commented: Not sure why you're rolling your eyes, but good solution. :) :) :) +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Waltp

This is not an english classes or forum. i dont like that.! Take things easy will you?

No it's not an English class. As for an English forum, whether you like it or not, from the Member Rules:

Members who break a rule will usually be warned, [this is an infraction warning] followed by a points-based infraction for subsequent offenses. When a member is given an infraction, they accrue points which remain on their record for a time period....

Keep it Clear
* Do post in full-sentence English
* Do not write in all uppercase or use "leet", "txt" or "chatroom" speak

After a 1.5 years and 430 posts, you should be aware of these rules by now.

And rather than getting an infraction, which is completely justified, he has been warned outside that system, giving an extra chance to keep it clear. More than fair, eh?

Nick Evan commented: Good point +16
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And?

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

Since you like to be repetitive:

Do you know how to copy from one array to another? You should, after your other thread.

All you need to do is take that solution and modify/expand it to fit this situation.

Fbody commented: :D +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Oh i didnt knew thr is scanf function :D

He said he couldnt use it and wanted some other way ..

No, he said:

but this function [ scanf() ] is not found in # include <stdio.h>

which is completely wrong. It is in stdio.h therefore available to be used.

vedro-compota commented: + +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then look at the last characters of each word and compare them with your list of AY sounds.

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

#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <iostream>

This won't work at all using most compilers. I dare you to try it on VC++. Using O/S and compiler dependent solutions are problematic. These include
* system("pause"); * Any Linux/Unix-only solutions: unistd.h and termios.h * Non-standard C function getch() , defined only in particular compilers on one O/S


The BEST answer is the original post in this thread. Please learn and understand why. Don't just post your favorite inadequate solution as the best way. In these forums we try to teach the proper way to do things, not the hackneyed way most people are taught by less-than-adequate programmers.

More here

Flaming another contributors post is definitely not the way to go about gaining a great reputation here.

There was no flame. The suggestion of system("pause"); is shitty. Nothing against you, just that suggestion.

cout + cin.get() is all you need in C++
printf() + getchar() is all you need in C

printf() is a huge hit on resources. If all you are doing it printing a character or a string, use putchar() and puts() repectively. :icon_wink:

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

Do you really need help counting the characters in the string? Look at the methods associated with a string object.

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

To all those here asking for us to give them free code --

That's not how these forums work.

You do the coding. You post what you have that doesn't work. We help you fix that code. Do not post code that simply has a comment that says "// this is where I need help"

jonsca commented: Make this post a sticky! +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Microsoft says what I wrote above: http://msdn.microsoft.com/en-us/library/29dh1w7z%28v=vs.80%29.aspx

Since M$ is only concerned with M$, what they say is perfectly valid -- for the M$ world. But they are not the only game in town, and these forums cater to all games, not just the M$ world. Hence, portable has a different meaning.

IOW, portable does not mean "Works with Microsoft" here.

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

When you want your program to be portable

Excuse me? Don't you mean not portable?

You wouldn't use them. IMO, they are unnecessary.

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

That's because you didn't learn C++. You learned C. And if your instructor was really teaching C++ then you unfortunately received a very bad education. It's like taking a car repair class and all you worked on were motorcycles. After all, they have engines, too, don't they?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
const int DAYS = 7;
const int TEMPS = 2;

for (int days = 0; days < 7; days ++)
{
    cout << "Enter High Temp for day " 
         <<  days + 1 << ": ";
    cin >> xTemps[DAYS][TEMPS];    // This always loads xTemps[7][2] --
                                   // which does not exist.  Max is 
                                   // xTemps[6][1]

    cout << "Enter Low Temp for day "
         <<  days + 1 << ": ";
    cin >> xTemps[DAYS][TEMPS];    // Overwrites the above.
		  //end for
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

//Why did the compiler treat it as a function...

Because it IS a function.

... and are the header files lacking or what?

No, you are lacking the header file.

But why do you want to use a non-standard C function when a standard C++ function works just fine? Use cin.get() Also, main() is an int function, not a void function. See this

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

What you're asking doesn't make sense.

I'm aware you can use putchar() but that doesn't really work so well for what I'm doing,

Why? Are you trying to output a character and it's outputting a flower? Maybe you need to be more explicit so we can understand what you're doing.

or at least I'd like to find a quicker way if there is one.

Huh? What's quicker than putchar() ?

Is there not a tochar or basically the opposite of toascii?

No, a function like tochar() is worthless.

A char and it's ascii value are identical. It's just two different names for the same numerical value. Like hot dog and wiener.

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

Who's teaching these people computer lingo????

My program runs a three dimensional maze (3x3x3 = 27 locations)...

No, it creates a maze. It doesn't run anything.

... the start and exit rooms show up on the run compiled program ...

A "run compiled program?" What the heck does that mean? Run from the IDE?

... but the code room does not cout?

Things don't cout. Things get displayed. A ? is used after a question, not a statement.

However if run from the executable created it shows all three rooms, re-running of the compiled...

The executable created is the compiled...

It compiles fine apart from this ...

It compiles fine because you have no syntax errors. Logic errors do not affect compiling in any way.

... and I am not sure if somehow I've coded it wrong, although then it should have thrown up compile errors?

If it doesn't do what you wanted, you coded it wrong. If you write your code wrong, how is the compiler supposed to know that? If your code is cout << "Yellow Woild" << endl; , do you expect a compiler error because you misspelled Hello World?

do {
   time_t now;
   time(&now);
   srand(now);

srand() and all this time stuff should be at the top of the program, not in the loop. All you are doing here is resetting the random generator to the same value, which generates the same random values each time the loop runs. …

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

Then you did it wrong. Are you really asking us to write it for you? We can't help you fix it if we can't see what you did wrong.

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

Would a statement like

When posting programming code, encase it in [code], [code=syntax], where 'syntax' is any language found within our Code Snippets section, or [icode], for inline code...

be what you're looking for? This is at the top of the C and C++ forums at least.


How about

Use code tags!

There are two ways to wrap code in code tags. The easiest way to do this is to select all of your code and then click the # button on the message editor. This will automatically wrap the selected text in code tags. Without code tags, all leading whitespace will be removed from the code, so nicely formatted code ends up having no indentation. This makes the code very hard to read and many members will refuse to help you because they can't read your code.

This is in the sticky post Read This Before Posting. Yes, it needs to be edited to reflect [CODE] instead of #, but this has been available also for a long time.


The Member Rules (link at the top of every page) state

Keep it Clear
* Do wrap your programming code blocks within [code] ...
[/code] tags

On the background of the text box where the questions asked are typed in is:

Please wrap code in [code] and [icode] tags
Here is php code: [code=php]echo ":Hello World";
[/code]
Here is c code: [code=c]printf("Foo\n");
[/code]
Here is …

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

First, after entering the number, calculate the number of days.
With what's left after removing the number of days from the number, calculate the number of hours.
Keep going until you get the seconds.

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

Yes, we can help you.
Yes, it is a silly request since you didn't bother to give us any indication what you need help with. We don't code for people, we help you fix your code.

Be sure to read the Member Rules.

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

You can't use .eof() in this manner. You don't hit EOF until you actually try to read past end, not when you read the last character. Therefore, you will go through your loop the final time after reading bogus data.

Read the first characters before the loop. Then read the next characters at the end of the loop.

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

For the third part of the question, set the 3rd array to all zeros. Then you can simply use the element in the first array num[i] to increment the proper element in the 3rd array: dist[num[i]] In other words, if first array contains:
num[]= 2 4 3 8 5 3 4 2 8 4

the 3rd array will contain
ctr[0]=0
ctr[1]=0
ctr[2]=2
ctr[3]=2
ctr[4]=3
ctr[5]=1
ctr[6]=0
ctr[7]=0
ctr[8]=2
ctr[9]=0

You don't need the double loop.

The answer to the second question can now be loaded into dist[] just by looping through cnt[] and looking for != 0

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

Yes, cookies are required to contribute to DaniWeb.

I'll ship you a box tomorrow. Oreo or Chips Ahoy?

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

Because it's simply a pointer to a single char, there is not sufficient memory allocated where that char is stored to hold an array of char.

Actually, there isn't even a single char. It's just a pointer to nowhere in particular.

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

If you enter the number 2651, they will fill
A[0]=2
A[1]=6
A[2]=5
A[3]=1
You just need to move the values so you have
A[0] to A[24]=0
A[25]=0
A[26]=2
A[27]=6
A[28]=5
A[29]=1
and so on. 2 simple loops and a little thought will help you accomplish that. Look at the pattern above.

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

I have no idea what newToCheck is for.

Line 8 defines it as a char pointer. No size so there's no storage.
Line 29 seems to serve no purpose at all.
Line 31 uses newToCheck[n] but the location has no storage space, so even if you tried to run the program you'll probably crash.

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

Write some code already!!!!
Read a line of text.
Write the line of text.
End of program.

If you hadn't wasted the past 10 hours BSing and trying to convince us to write it for you, you'd be on to the next step already. As it's going, you won't be there until Friday.

Nick Evan commented: Yep. +16