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

You'd be better off reading the entire line and looking through the array rather than trying to mess around with complex file reading techniques. If you can read the entire file, so much the better.

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

Set the textbox ENABLED property to FALSE. The WebBrowser probably has the same value.

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

Look up the functions RIGHT() LEFT() MID() and LEN().

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

it is already included mate

Look again, mate...

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

I noticed you guys on this forum don't use

using namespace std;

but I thought it was more a matter of style other than anything else...

You will notice if you actually look at this forum that we DO use using namespace std; . Many of us don't necessarily subscribe to the idea Moschops set forth here. Note he only has a few posts here and therefore speaks for himself, not the forum as a whole.

This is not to say his idea is incorrect. Only that it is not a forum wide policy.

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

Congratulations.

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

What you did is perfectly acceptable.

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

Another example:
You want to know what lights are on in your computerized home.
Bits:
0- Front Porch
1- Entryway
2- Living Room
3- Dining Room
4- Kitchen
5- Bathroom
6- Master Bedroom
7- Kids Bedroom

In the lights byte you have

Byte value  00110101 
Bit numbers 76543210

Which lights are on?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
puts("please enter a file name to create:\n");
scanf("%s", &file_name);    // Never use scanf() to read a string.  It's dangerous. Use fgets()

if( create_pointer = fopen(file_name. "r"); 
printf("file already exist"); 
else
{
if(create_pointer != fopen(file_name"r");   // Didn't the previous fopen already check for this?
create_pointer = fopen( file_name, "ab");
}

You'd want to:

open file for read
If opened
    close it
    set flag to 'exist'
  else
    set flag to 'not exist'
endif
--continue--

But, based on your examples, if you are opening the file for append ("ab") why does it matter? The file will be created if it doesn't exist.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
void digits(int)
{
int n

cout << "You entered the number" << n;
return;
}

So what is your parameter variable? All I see is a parameter type, not a variable.

And since your examples don't use a parameter, keep looking at more examples -- preferably one that has a parameter.

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

You've been told twice that your digits() needs a parameter. jonsca even provided you with the format of a function. Now, go back to your book, look at the section on functions and read it. Look at the examples. Then try to make digits() look like those examples.

If it still doesn't work, post a very detailed explanation of what you tried and what happened. Your explanation:

when i place int there i run into the problem where it either error you get set a int to a character or too few arguments and any of my ideas to make an if else statment in my funtion to compare the int to

is not helpful to us.

Also, note that your instructions say:

The function should not return a value

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

Or, since now and bday are both in seconds, use subtraction rather than calling a function.

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

You need to stop thrashing about just trying things, and not understanding what you are using. Everything you need is in the time.h header. Find an explanation of the functions and structures it contains (GOOGLE) and read it. Then you will be able to do this task with ease. It's just a matter of calling the correct function to get your birthday value and subtract it from your TODAY value.

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

You need to look at the format of your IF statements. They are malformed.

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

sorry, you maybe didn't see my edit, but would you be able to answer my other question? Thanks alot.

That's why you souldn't edit posts except to correct mistakes...

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

Start with (in your case) the hardest test first.

if line is blank
   exit loop
else
   if line is #
      convert it
   else
      bad line
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

I think it could remain a stickie. as for "confusing the newbies" I doubt it. They obviously just ignore them for the most part. Can't get confused when you don't bother to look... :icon_confused:

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

Be honest --
When did he dump it on you?
When is it due?

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

That's because it's conio.h. But keep it commented out. You shouldn't be using it anyway -- it's not a standard header and if you get used to using it, when you change compilers you'll have problems because all your conio.h functions will no longer exist and you'll have to weed out all those functions from your program.

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

Start outputting values to the screen.
Watch your loop value as it increases.
Watch your word value as it's tested.
Watch the character being looked at during each loop.
Run through the loop one character at a time (pause at end) and make sure all the values are as expected.

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

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

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

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

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

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

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

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

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!

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

time() returns a type time_t srand() wants an unsigned int
Look up casting in your book.

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

Wow! That's a lot of code!

I agree. Over 1000 lines of code with no indication of where the problem could be. That's why I for one ignored the question. I already have a full time job and don't need another one being a code maintenance technician -- unpaid no less.

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.