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

Decimal places require float or double variables.

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

The program will stop if any other integer is entered except 1-4. My next question is this. Is there a way to ask the user to reenter the number instead of just ending the program?

Yes. You put the input in a while loop and don't exit the loop until a correct number is entered:

for(i=0; i<People; i++)
    {
        cout << "Person #" << i + 1 << ": ";
        cin  >> PeopleTypes[i];
        while (PeopleTypes[i]>4 || PeopleTypes[i]<1)
        {
            cout << "This is invalid input!\n\n";
            cout << "Person #" << i + 1 << ": ";  // input number again
            cin  >> PeopleTypes[i];
        }
        if (PeopleTypes[i]<0)
        {
            break;
        }
    }

I'll let you work out how to implement the <0 exit...

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

And would it kill you to use some indentation (or indeed any white space).

Exactly. Study this.

Salem commented: Nice link +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is there something about the background text you didn't understand on the input box. or the Read Me: Read This Before Posting link at the top of the forum?

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

Why is LetterToMatch defined as an array of one char? Why not just define it as a char and it won't be a pointer, correcting some of the errors.

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

Write another function that simply prints out the double values by converting to ints. Then at all places you output the values, call the function instead.

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

please reply to me if it is correct or not

Obviously not, since Narue added the code tags for you. And you did not explain what your problem is. When someone suggests you read something, you should do it. Go back and read Salem's link -- and also read this

sorry, i wasnt able to give attention to the watermark..T_T

Why not? It was put there for you...

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

Can someone tell me what i'm doing wrong:

Depends on what you're trying to do, what it actually does, and what it's supposed to do.

Can someone tell me what i'm doing wrong:

Formatting for one.
Explaining nothing for two.
Not posting errors for three.
Read this for further help.

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

OK, based on what you told us, you define an integer (say binary) and you enter only 1's and 0's into the variable. Your binary value is really read into a decimal variable, but contains only 1's and 0's.

Zero out another variable (say decimal) to hold the decimal value.

Next, using the % operator, get the each digit (a 1 or 0) and multiply each by the proper power of 2 and add it to the decimal variable.

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

not necessary, just declare another int named count , initilize it to 0, then increment it in that loop maybe something like this:

for (i=0; i < MAXGRADES; i++, count++)

Then replace for (i=0; i<MAXGRADES; i++) with this for (i=0; i<count; i++)

Or to make it simple, specify the first loop as for (count = 0; count < MAXGRADES; count++) This will automatically count the grades entered, and you won't need i at all.

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

I read in the binary form "011010"

As a string or a number?

I having trouble getting it into digits,

This depends on the answer above.

and assigning that digit the value in decimal form.

Explain what decimal form means -- with an example.

It would really help if you posted your code so we know what you're doing. Most of the terms you use have multiple meanings and/or are ambiguous and/or used incorrectly so your meaning is vague. Read this.

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

Look closely at one of the errors:
error C2664: 'read_data' : cannot convert parameter 1 from 'double' to 'double []'

The prototype says:

int read_data(double angles1[],double angles2[]);

The first parameter requires an array of doubles

When you call the function:

int numpts = read_data(angle1,angle2);

what type of data is angle1? Is it an array of doubles? Now look at the error again...

That should get you started....

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

First of all, read this. Then explain what your problem is, don't make us try to guess. And be patient. We all have lives and don't live here at DaniWeb -- 13 minutes is not an appropriate length of time to get demanding.

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

Your problem is using the wrong way to test for the end of a file:

while ( !myfile.eof() )

See this ( feof() is the same as using .eof() )

Salem commented: A nice link of traps to avoid +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i do need help..someone to help me et tell what to do? thanks

Sure... Read This!

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

It's because cin >> leaves junk in the input buffer when the command is finished. Use getline() instead, but you will have to remove the trailing '\n' that's in the string you read, which is an easier problem to deal with, IMAO.

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

As a simplistic explanation, each time you call the recursive function, a new copy of the function is created, including new variables. The values of the variables in the previous copy are not destroyed, so when the new function returns, the values are as they were before the call was made.

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

So why not use

cout << "The first and third letters in the entered words are: "
     << static_cast<unsigned char> list[1][1] << list[1][3];

to display the 1st and 3rd letters of word #2?

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

The assignment is :

This is so crazy, here is what I've got so far:

So what is it you need help with? You need to ask a question so we know what you need help with. Just posting unfinished code and the assignment says "finish this for me, please".

So what's the problem?

One thing I did notice, though, 1/3 is 0, not .33333. But 1.0/3 will work.

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

I just did a quick check and found the following :icon_twisted:
(this is mostly just in fun, don't get your knickers in a knot)

Some of my old problems are back                    Sep 29th 2007 3:38 pm
Cursor is disappearing                              Sep 6th 2007 6:27 pm
Scroll arrows won't repeat.                         Sep 6th 2007 6:26 pm
Enough is enough!                                   Aug 31st 2007 11:00 pm
Bumbling highlights square.                         Aug 31st 2007 8:27 pm
Get rid of the editing time limit!!!!!              Aug 25th 2007 8:51 pm

So over the past month you've complained a lot about problems (real and imagined)

You seem to have taken the summer off, but in May posted:

Stuff has stopped working.                          May 25th 2007 8:43 pm
Can't read what I am posting                        May 25th 2007 8:40 pm
Pages are jumping crazily around                    May 11th 2007 4:18 am
Dropdowns close when cursor over link underneath    May 8th 2007 4:39 pm

Just find it interesting.... :icon_wink:

~s.o.s~ commented: Heh, nice observation. ;-) +21
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Assuming a solid rectangle, you have nested loops: outer loop counts rows, inner loop counts columns; inner loop contains output of char1, at the end of the inner loop you output a newline.

A typical loop would be such like this.

for ( int r = 0; r < rows; ++r ) { /* loop body */ }

Thanks for a quick reply!, however I'm VERY new to C++. So, I will appreciate whoever is able to elaborate a little bit more.

Orium.

A nested loop means a loop within a loop:

for (row = 0; row < 3; row++)
{
    for (col = 0; col < 5; col++)
    {
        // here you output your character
    }
    // here you output a newline to finish off the row
}

The inner loop would display an entire row of characters, and the outer loop controls the number of rows you want to print. The above might print something like:
#####
#####
#####

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

Any suggestions? Anyone?

Yes.
1) Use code tags as explained on the background of the box you typed you messages in, as well as in the Forum Rules
2) Don't bump your threads. It's rude, and most of us have lives outside of DaniWeb. We'll get to your problem when we get to it.
3) Explain you current problem. Saying you fixed something and posting new code does not tell us what's wrong now.

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

hey there;
i wanted to write a program to convert binary to decimal.
i did that using the " character approach".
it works just fine.
then i decided to enhance the program by adding an error message whenever the input are invalid (i.e anything other than 0, 1 ), but i havent been able to figure it out yet.
i've been playing around with it but it is still not coming.

I must be missing something because there seems to be no attempt in the posted code to deal with invalid input. We therefore can't tell what you are doing wrong.

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

>Since 'A' is the internal value 65, 'B' is 66, 'C' is 67, and so on,
>subtracting 'A' from your letter will give you 0, 1, 2, and so on.
This is a non-portable assumption.

True. I forgot that his school may be learning on an IBM mainframe, rather than the universally accessible school and home computers that run ASCII. :icon_rolleyes:

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

A couple problems with your functions:

int readBig(int[])    // what's the variable name being passed in?
{                     // same with addBig()
    string num;
    int n[MAX_DIGITS],i;
    cin>>num;
    for(i=0;i<MAX_DIGITS;i++) // what if you enter less than MAX_DIGITS digits?
      {
        n[i]=num[MAX_DIGITS-1-i]-'0';
        cout<<"n["<<i<<"]"<<n[i]<<"\n";
      }
// This is an INT function -- you must return an int
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since 'A' is the internal value 65, 'B' is 66, 'C' is 67, and so on, subtracting 'A' from your letter will give you 0, 1, 2, and so on. Therefore:

int idx;
int notalpha=0;
int nchar[26];
for (...) char[i] = 0; //set each char to 0

while (c ...)
{
    if (isalpha(c))               // is it an alphabetic character?
    {
        idx = toupper(c) - 'A';   // Subtract A to get an offset from 0 
        nchar[idx]++;             // use that as an index into nchar
    }
    else
    {
        notalpha++;
    }
}

printf("A = %d, B = %d, ...", char[0], char[1] ...);
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This may help.

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

well in the function "add" I want to add "b" to the specified number, and in the function "deal" I want sign "y1" to "b" in "add", so that "y1" will also be added to the number, and the same thing goes for "y2".

but if I put in function "deal":
cout << y1 << " " << y2 << endl;

this comes out:
0 1190668742

Since you never initialized y2, you start out with junk in it. Initialize y2 before using it.

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

Here at DaniWeb, we perfer to:
1) use code tags when posting code
2) read the rules so you know how to post
3) not give ready-made programs but help people learn how to program
4) post good code when helping, not bad code, like:
getch(), void main(), proper formatting, and proper headers (.h-less headers rather than old ones)

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

Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25.

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

This information will help us help you if you follow the suggestions therein.

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

strstr() does not work on string class, only char* s. Look at the string class methods to find your substitute function/method.

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

basically, when i try to insert a number for minutes, such as 73.5, it will say 1 hour and 13 minutes late, leaving off the .5 .....thank you for all your help

First of all, why would you want to keep track of .5 minutes? Make them all int s, then the formula becomes

hours = minutes / 60;
minutes = minutes % 60;

Now you have total minutes converted into hours and minutes

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

can someone tell me how to find dummy tutorials on how to compile and run C programs using a text editor and the Command Line Window.

You don't really need one.

Type in the command you use to edit a program.
When the program is ready, type in the command your compiler suggests to compile the program.
When compile is clean, type in the program name and it runs (or blows up, depending on how good your code is :icon_wink:)

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

I am having trouble formatting my output of decimal to binary conversions...

Wouldn't it be beneficial to let us know what kind of problem you are having? The output you posted is correct.

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

another error need help please??? Is that the type of title suggested by the Read This thread at the top of the forum? And is the information you gave adequate for our understanding, as the same post suggests?

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

One more thing...
Forget threads for a moment. My wife runs a business with many customers and contacts, and needs a database type application. I want to put my C studioes into practice. Will this be a good practice for me or a waist of time?

Eating a bunch of chili dogs would be a waist of time, but programming a DB system would not necessarily be a waste of time :D

I'd say go ahead an program it. But because you're new to programming, I wouldn't expect it to actually be used in her business. That would be a little much to ask from a business standpoint. But for practice, she can help you design the system, test out what you do, make suggestions for improvements, and suggest useful functions. This would be great practice.

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

I want to be nearly The Quee..... King of Daniweb.:zzz:

That's a lofty goal for an unknown quantity :icon_wink:

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

I wrote one as follows.

string line;
	ifstream fileread ("[I]path to the binary file[/I]");

	while(! fileread.eof())
	{
		getline(fileread, line);
		cout << line << endl;
	}

	fileread.close();

Well I read a binary file using this, the command prompt is really mad. It,s not displays as a binary code, I mean bunch of zeros and ones.

Can you say where I'm going wrong.

Two problems:
1: Binary data is not string data. You should probably be using a char array.
2: while(! fileread.eof()) will not work properly. See this ( feof() is the same as .eof() )

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

please help me in finding what is wrong with my array... its not sorting
thanks, thanks.

First, what Ancient Dragon said is correct.
Second, your sort needs two loops, not one. Look at the description or algorithm of the sort again. Your code should be moving the highest value into place (once you fix the loop parameters). Then add that second loop.

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

The Law of Projects:
The first 80% of any project takes the first 80% of the allotted time.
The last 20% of the project takes the other 80% of the time.

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

That being said, Intel is quite liberal with their documentation so there is no reason M$ couldn't have an equal or better compiler.

There's a good reason. They're M$. This generation's IBM. If they could program like they market, you'd be right. But all they really have going for them is great marketing and a stranglehold on the industry.

SpS commented: :) +4
Hamrick commented: great marketing alone doesn't keep you in business for several decades +0
Aia commented: Hamrick, repping is not an instrument for opinions. +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I found out what the deal was.... instead of creating a new source file, i created a new project. When creating a new file, my tool writes this in the file as part of the template:

system("pause");

Edit the template to get rid of that awful command. I did... :icon_wink:

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

I know it's been suggested before, but a beta.daniweb.com would, in my opinion, be a vast improvement. You'd get a good idea of what kind of feedback you'll receive when you release it to the public, you could select users to test out your new changes, and once you've as many bugs as you can ironed out, release it. For users, it would mean learning the updated UI less often.

This I agree with -- for changes that actually affect usability. Moving buttons, changing fonts, things that make the site different in operation or strong visual changes.

That's definitely by all means standard for software. However, when was the last time you saw google.com or digg.com or cnet.com or any other large website for that matter publically release such a document? The answer: they wouldn't.

I rarely see them make small changes on a daily basis. They may innocuously tweak something, but when large changes get rolled out all in one shot, and I'll bet it's only after a strong beta-test from select users. They are (probably) never implemented so that the entire user base sees them for the first time.

So that I won't be accused of failling to mention it, a UI change made today was to surround the list of sticky threads with a thin box to separate them from the regular threads a bit more.

This is something that can be done 'on the fly' because …

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

Dave, at least you have a viable reason. Most other reasons I see given here is simply because it's old. Not a valid reason IMAO.

My preference would be to stop telling people "your compiler's old, so upgrade to [my personal favorite] compiler." If that's what they are using, let them use it unless it's really crap (like Digital Mars).

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

Yes, and...? Not only did you not ask a question, you did not even make a sentence.

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

It used to be. Try asking at http://www.borland.com/newsgroups. Someone there should know...

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

In general, you have to assign a specific date to be your ultimate beginning date. Then you calculate the exact number of days from that day to the day entered by the user. Then you can calculate the day-of-the-week from that value using the modulus (%) operator.

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

Actually, you don't need to understand allocation at all. The instructions say:

The file contains 10 columns and many lines.
...
It is assumed that number of students is no more than 100

So all you need is an array of 100 lines of 10 columns.

If you know structures, you can create a structure that contains
-- Student's Name
-- Array of 9 scores
Then make an array of 100 of the structures.

If not, make 1 array of 100 character strings of a maximum size for the names. Something like char names[100][21]; for 100 students with a maximum of 20 characters per name.
Then make another array for the scores, like int scores[100][9]; Since you know the exact format of each line, in a while loop, use fgets() to read an entire line. Then use sscanf() to break the line into the structure or the arrays.

Aia commented: Nicely taught. +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The problem is unlikely to be with their code but rather ... you're using the outdated version of turbo c, which is probably very likely :)

So you claim that the outdated versions of C/C++, like Turbo, never handled strings correctly? :icon_rolleyes: Or is it that after new versions came out, the older versions simply wore out and developed bugs?

If you're going to continue to slam older compilers, at least use reasons that make sense...

iamthwee commented: B I N G O! +11