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

Then originalPointer is getting too large. What is in the array inputText? Not what you think is in it, but what actually is the value of every single element in the array? Print it out value by value, as integers, and make sure the last word in the array is set up properly for your testing loop.

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

what's in the header file that's called "conio.h"?

for the
int getch(void); (amongst others)

The real question is why is the O/P using a non-standard C function from conio.h in a C++ program when a simple cin.get() will suffice?

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

This is not quite right: You need to restrict the swapping so that the destination position is always >= the source position.

int rowToSwap = a random valid row that is >= row
int colToSwap = rowToSwap == row?
    a random valid row that is >= col :
    a random valid row

To see why, consider what happens if there are only two elements in the array using the original strategy. We look at the first element and swap it with the second with probability 0.5. Then we look at the second and swap it with the first with probability 0.5. The net effect is to keep the original ordering 3/4 of the time. Not a random distribution.

But, since the array contains 12, no need to consider the 2-element problem. If there is a chance of a 2-element array (say via user input for size) it then becomes important. And the simple fix is to just go through elements-1 rather than all that testing because the only thing that testing does is remove the last element from being randomized, doesn't it?.

Although, looking at your algorithm:

int rowToSwap = a random valid row that is >= row
      int colToSwap = rowToSwap == row?
          a random valid row that is >= col :
          a random valid row

how can you really assign colToSwap to a valid row? you have a major chance to blow your array if #cols < #rows, and completely ignoring values if #cols > #rows even …

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

Hi, I need to open a file containing string values one below the other and display them.
I'm able to open the file but there is some error while displaying them.
Below is my code, kindly guide me to my mistake.

Then you made some error programming the code. Your mistake is not telling us what the error is, and what line the error is on.

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

You didn't specify -M or -MM on the command line would be my guess.

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

Probably.

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

Does s contain the file name you want to open? If so, use it in your fopen() statement.

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

If it's not part of your compiler, it won't work even if you do find it. Adding a header does no good without the associated code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
static int is_valid_dice_selection (char input [])
{
    char input[i];
    int length;
    length = strlen(input);

    for (i = 0; i < strlen(input)-1; i++)
	{


	}
	return 0;
}

This function is not needed if you're going to do all the checking in select_dice() .

static void select_dice (int reroll_flags [])
{
	int i;
	char reroll_input [NUM_OF_DICE + 1];

	do
	{
		printf ("Mark the dices you want to reroll with a X, the others with a -.\n");
		printf ("For example, if you want to reroll the dices 2 and 5, you'll enter: \"-X--X\"\n");

		scanf ("%5s", reroll_input);

Use fgets() instead. scanf() has major problems in this usage. See this Also, you don't need the next two line if you remove the function above.

}
	while (! is_valid_dice_selection (reroll_input));

	for (i = 0; i < NUM_OF_DICE; i++)
	{
		if (tolower (reroll_input [i]) == 'x')
			reroll_flags [i] = 1;
		else if (reroll_input [i] == '-')
			reroll_flags [i] = 0;
	}
}

Just before the FOR loop, set a flag to a TRUE value. Then if any of the 5 characters is not 'X', 'x', or '-', set the flag to FALSE. After checking all 5 characters, test the flag. Then you can loop back to input again if FALSE.

Alternative, move the FOR loop into is_valid_dice_selection() , with the flag.

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

OK, done. Took 5 minutes, 37 seconds (I type slow). Now what?

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

Narue@ code is horrible lol. i knw u ll say to use <iostream> instead of iostream.h and conio.h is non standard header file..etc lol i knw everything but im using TURBO C++ version 3.0 it require these things

conio.h is not and never has been required.

If you know everything, then write your programs as properly as possible and use proper English. "i knw u ll" is not proper English.

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

And?

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

Calling time() returns an integer. Look it up.

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

You resurrected a thread that's been dead for 18 months to give this completely lame answer? How is the date returned as a string to main() as the O/P requested?

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

I will consider re-adding the multiple reply button.

Thank you :icon_mrgreen:

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

1) By always outputting and inputting the exact same format in each file. chargold is always, say, the third value read.

2) By outputting the name as you output the value: fdat << "chargold=" << chargold << endl; Then as you read the file, when you read "chargold=", the data following can be moved into the variable.

Personally, I prefer #1. It's easier.

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

So the e in include is using i before definition and the d in stdio.h is a function call missing?

Sorry, but this is like pulling teeth. If you want help, you MUST give us all the information necessary to understand the problem. Not bits and pieces that are useless without the rest of the information.

Copy and Paste everything that will help rather than paraphrasing which leaves out important clues...

And learn to format your code

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

OK, now maybe you can tell us what lines the errors are on.
:icon_rolleyes:

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

So initialize the matrix to all 0's first.

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

Sorry, I can't see your screen from here. It might be nice to let us know what errors -- or should we guess?

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

For example, try this:

#include <stdio.h>
int main()
{
    int i=-1;

    for (i=5; i > -5; i--)    
        printf("%06X\n", i & 0xFFFFFF);
    
    return 0;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As the OP said,

I'm trying to get it to output fewer bits: e.g. 24-bit: FFFFFF In fact, the output I want needs to be 6 digits in all cases.

Clearing out the top 8 bits effectively gives you a 24 bit value. Therefore, 6 digits can be output.

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

That sounds even more convoluted.
You could clear out the bits you don't want: i = i & 0xFFFFFF; to make the value 24 bits.

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

Please explain in detail. I, for one, am confused by your request.

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

I've never had a problem with double posting as long as new useful information is posted, or quoted responses to multiple posts are being done. It's bumping that irritates me.

I do miss the multiple-reply button. Many times I want to reply to more than one post in a thread and doing it now is cumbersome. I do that to avoid double-posting.

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

It is proper English, it's just not used often. It will rarely if ever be spoken. When written it feels like formal English rather than a more colloquial form.

You need Adobe Flash Player 8 (or above) to view the charts. It is a free and lightweight installation from Adobe.com. Please click on Ok to install it

scans better for me. The same feels klunky.

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

This is not something Standard C++ is not able to do. You have to call some functions from the operating system, or some very non-standard functions that few compilers have implemented.

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

It's poor because of

#include<conio.h>
void main()
clrscr();
getch();

And the formatting is only fair.

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

Maybe...

What happened when you tried it?

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

And your question about this poor code is... what?

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

xiilin seems to be the only intelligent person posting in this thread! Use scanf() as suggested.

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

Just add up "5 Total duration of call in minutes" as they are calculated.

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

My question is how can i ask the user to enter a certain hour of his choice e.g.
11:05:03

cout << "Enter a time in the format hh:mm:ss -- " << endl;
cin >> GetTime;
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please learn to format your code properly. It's very difficult to follow.

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

You're still blowing past your array. You need to stop 'playing' with the index. If you make a 10-element array, loop from 0 to 9, not 1 to 10. And don't add/subtract from the index.

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

You close it. It's your thread.... Just mark it solved.

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

I'm sure they will. Sorry guys...

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

To satisfy these requirements

2. If user is trying to enter more than a N*N numbers, system will throw him out with an appropriate message.

3. If user provide less than a N*N numbers, system will throw him out with an appropriate message.

you need to loop simply waiting for an EOF. You don't want to do your input based on N.

4. If one of the values (or more) is not an integer, system will throw him out with an appropriate message.

Two ways to handle this.
1) Test the return value from your scanf() to see if an error occurred
2) Read all input as a string and test for digits only (use fgets() for this, do not use scanf() )

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

How would you do it on paper (IOW, how did you generate the above patterns?) Think carefully about your decisions when and how to use spaces and stars. Look at the patterns and using jonsca's hint you can translate your pattern into code.

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

Who made your rules? I ask because they are not the standard translation rules.

1) All consonants at the beginning of the word are moved to the end and AY is added.
2) If the word begins with a vowel, WAY is added with no other changes.
3) There is no rule about the end of the word ending in the AY sound. This is a nearly impossible rule to test for. A computer program cannot test for a sound.

See this.

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

We can continue to play 20 questions over the next few days -- you giving us more vague ideas of what you need, us giving fairly worthless responses because we really have no idea what you are dealing with.

To make the process go faster, try giving us a very detailed explanation of what you are trying to accomplish and post a couple segments of code illustrating what we are dealing with. Don't forget to use CODE Tags.

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

Oh that's a great way to teach people how to program. I suppose if you every get a job you will expect eveyone else you work with to do your work for you so that you can sit on your ass and play with yourself.

And he had to resurrect a 3-year old post to get PO'd at. He could have found a few newer ones methinks...

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

It's too complicated. If all you are doing is adding two large numbers:
1) read the numbers as you did, have one more array for the answer.
2) convert each character digit to a numerical digit (hint: '3' - '0' = 3)
3) start at the end of each number and add the values. Keep track of carrys as you move left to the next digits.

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

Oh, ghod! Another one of those ridiculous suggestions to a student use a vector instead of an array. A vector is a higher level object and if you can't use an array properly, vectors are not the solution. The solution is to learn to use an array! Learn vectors when you understand the easy stuff!