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

We are having problem with our code regarding file streaming.

No, you are having problems with your code because you are doing very bad things: void main() -- MAIN is and always has been an int function. See this. exit(1); -- is there something wrong with a simple return(1) ? system("Pause"); -- see this main(); -- Never NEVER call main(). It is an entry point to your program and should not be used as a recursive function! main(); -- and again main(); -- and again

in void input() -- main(); -- 3 times

in void equate() -- main(); -- 3 times

in void display() -- main(); -- 7 times

etc...

In these functions, a simple return should be used, and when the function returns, test the error code you set.

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

and where do you get the ln() function? From math.h? Which can't be used?

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

My programs are running fine..But I don't know whether quicksort and selections sort are stable sorting algorithm.....If I know will conclude that my programs are correct.

So how do you find out whether they are stable? As I said before

Try more tests. Bigger tests. That's how we all discover if the programs work properly.

And in this case, since your programs are running fine, that's how we tell if the sorts are stable.

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

Try passing "a 2-D array a size for the number of" rows, not columns

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

Never define variables in a header file (.h)
They go into source files (.c)

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

Your code still has no formatting so it's still hard to follow.
If you really want us to "Just go through the first if to understand what the program is about" I suggest readable code. See this. I also suggest since you don't wish to explain your code to us, comment it heavily. Reading someone else's code is not a task we take lightly. It's work.

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

Can you absolutely guarantee that for all compilers on all systems !(count <5) will be 1 or 0? Is 1 a definition of TRUE or is non-zero the definition in C/C++? Tricks like this can be dangerous...

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

Regardless of what the author of this code intended, what it actually does is this:
This function fo() prints out the value of count, and the value of count will be increased by 1 if it is less than 5 or else it will be increased by 2 if it is greater than 5. In other words, this is what this code is doing:

If(count < 5)
   count = count + 1;    // Increases the value of count by 1.
Else
   count = count + 2     // Increases the value of count by 2.

cout << count;           // Prints the value of count to the screen.

So count is either increased by 1 or 2 depending on whether it is less than 5 or not.

Or more succinctly:

count = count + 1;    // Increases the value of count by 1.
If(count >= 5)
   count = count + 1;    // Increases the value of count by 1.

cout << count;           // Prints the value of count to the screen.

:icon_wink:

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

Call computeSphere(r, &a, &v); & will pass the address of the variable and the value can be changed in the function.

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

No WaltP. The program on very top was given to us by our teacher and assignment is to add arrays or functions to it (it have to have either one), also other techniques like string. i added string already. MY question is where can i add arrays, after adding arrays the program should display appropriate message like its dong righ now.

Thanks.

You didn't say that before.

Well, the way you add arrays is look carefully at the program and find a group of variables that together work quite similarly. Is there a way to convert those variables into one array?

Is there a a series of values you do the same work on, replicating the code over and over? This points to a possibility where a loop and array can be used once instead of multiple times.

In this program, a,b,c seem to be excellent contenders for an array. And your IFs can be converted to 1 or 2 loops.

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

First things first...
Get rid of *ALL* system() calls. Clearing the screen is not necessary. Calling the operating system command PAUSE is bad. If you want to pause the game, just do a cin . It's part of the language.


Second (you may as well learn this now rather than pull your hair out later)...
Each and every time you read a single character, notice you hit the ENTER key? That is also a character, so you end up leaving junk in the input buffer for the next read -- which is rarely a good thing. Search for ways to keep the input buffer clean of junk after each input.

Third is your design.
If you don't design your program before you start coding, your code will be terrible, your program will have holes in it, it will be difficult to get parts working smoothly together. And in the end you will end up with this instead of this

In your case
- what does the game look like?
- what does it do?
- how are the 'rooms' designed?
- how are they linked together?
- how do you handle input?
- what are the commands?
- how do you translate input into commands?
and so much more...

If you want to see how the original text game works, complete with source code, see this page. Code …

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

You're kidding, right? You want to now retroactively add an array? That's like deciding after your house is built that you'd really like a basement...

It should have been thought about in the original design before starting the program.

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

does this seem ok?i'm a bit confused..

Not at all. Use my technique. It's simple. tkud's solution needs a lot more understanding of files than you have at this point in your programming.

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

True, I just wanted to know if its okay up to now.

Couldn't tell you that. You're the one that ran the program. Did it look right?

Well the first thing is, I am getting to many responses on the output. EWhat can I do to change that.

Don't have a clue what many responses means. You know, showing an example usually alleviates a lot of misunderstandings and "have no clue" responses.

Next do I need to do a cout statement that shows two columns.

Example
cout <<\n"Response" <<"\t\t" <<"Ratings"

So output your 'response' and 'rating' with appropriate spacing between before you output your ENDL.

if one of them is ratings[index] what is the other and ...

That's up to you. What value do you want to display?

... how would I make them line up under each column.

Look up setw and other output manipulators.

Lastly the output of ratings should use asterisks, I have a function prepared at the bottom of the code, which I can insert to Prototype and call, but I tried and failed and just got a long line of asteriks instead of individual for each response.

void stars(int number)    // what is number and where do you use it?
{
for ( ; ratings > 0; ratings-- ) // what is the starting value of ratings?
 {
cout << '*';
 }
 cout << endl;
return;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Three programmers were walking down the street. Two of them walked into a bar. The third sidestepped it, laughing.

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

Try it and find out. Report your findings.

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

Everything that was written as possible solutions are not really good.
Downvoting...hmm that doesn't happen a lot (at least in the VB forums)

So? It happens enough. And even if in your opinion is doesn't happen enough, so what? Downvote them and it happens more? IMAO, your reasoning why you won't downvote is nonsensical.

Ignore list ... only hides the post of that user but not visible from the thread list. Also it could happen that this "ignored user" have replied to a thread with the correct answer and then im unable to see that and wasting time again, finding a solution, that already exist.

You asked if you can mark threads started by a blacklisted user. If you see the post is hidden, you can't possibly waste time reading posts from that person. And if you don't want to wast time reading their posts, why do you care if they give a good answer or not? Again, your reasoning make no sense.

Checking the users reputation before reply to a thread? yes sure if i want to spend all day doing check on every user who ask a question. Thats over the top.

If the forum showed us reputation like it used to, this would not be a problem. Now you have to mouse over the left side of the post to see it. I can see this as slightly annoying, so I'll give this one to you.

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

Then find a compiler that has documentation.

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

Because by definition and design of the language it is wrong. See this.

You must understand that just because something works fine does not mean it's correct. It is very possible to drive through a red light. It works. But various bad things could happen. And because the law says don't do it we don't do it.

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

I'm not sure I understand...

your first post seem to say
1) You want to make sure your sorts are stable.
2) You run both sorts on data and find out they are stable.
3) The code works for your test so far.
So what is your question?

Try more tests. Bigger tests. That's how we all discover if the programs work properly.

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

Sure.
Read the file until you get to the 'certain start line'.
Then continue reading and doing what you need to do with each line.
When you reach the 'certain end line', stop reading.

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

Read the list 1 value at a time
Put them in the array where you need them to go.

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are …
NathanOliver commented: I love this bolier plate help +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi,
I am trying to complete this application. just using a simple Array. I have most of the instructions down and included some additional stuff I thought was practical; it seems to work up to a point. I will continue to explain.

But you didn't continue. All you did was post requirements. You never did ask one question nor explain what you need help with.

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

Sounds like you might have your srand() call in the wrong place. It should be called only once a the start of main()

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

So, there's no one to help?

Your code has no formatting so it's hard to follow.
Your explanation makes no sense. All that "data" may be understandable to you, but it means nothing to us. I have no idea what

a1(operation)b1 resultingerror1(whose value depends on operation, but nevermind)
.
.
.
an(-||-)bn resultingerrorn(-||-)

even means.

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

Take all inputs as a character string. Then test the characters to make sure they fit your required input. If not, display an error; if so, convert to integer and continue.

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

can you please tell me some books and sites for reference...i want to learn HTML and web designing..from basics to higher level..so that i could design website

Try This

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You are very condescending. I'm not sure if you are trying to help or just make yourself feel better because nothing you have said has helped thus far. If I knew how to "format properly" don't you think I would have? I don't need to know what to do, I need to know how.

I post a link to an explanation on how to format properly and I'm condescending because you can't tell what a link is? I'll keep my real condescending comment to myself.

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

So? My comment stands... format properly.

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

I suspect if you properly format your code an error will show itself. I think because of bad formatting, your 4 nested for() loops are causing a problem.

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

Sure we can help. But with no effort shown on your part so far, all we can do it write it for you. If you need help you will have to give us something to help with.

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

I've narrowed the problem down to line 82, which is trying to read an array with an index out of the array range. I know this is a problem, but I would expect to see a garbage number displayed on the console and not my computer losing it.

Your computer isn't "losing it". It's outputting exactly what you asked it to do, filename[2] -- which doesn't exist. So it's outputting the stuff that's where the variable should be anyway, which is probably other data in your program space which can be just about anything.

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

That wasn't a rephrasing of the problem...

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

Use the program Visual-C++ Express. It's free.

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

Alright guys thank you, idk why I forgot to use spaces and what not. and the scope brackets some how i got very confused on placing them, thanks guys!

Here is the final code (and it works) Thanks so much:

Unfortunately, you code now looks terrible. And if "the scope brackets" confused you, I now see what your problem is. You need to study this and you will never be confused again about your brackets and spacing. :icon_wink:

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

Yeah? And how does that help in our understanding of your problem? Please stop ignoring my links.

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

The first question: this isn't a question. Did you leave something out?

The second question: what do you think the answer is?

You give us your answers and we can confirm if you are correct, but we won't do your homework for you.

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

Correct me if I'm wrong, but if there's no loop as Schoil-R-LEA points out, isn't it impossible to read more that 1 character when your input accepts only 1 character?

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

Other than no formatting making it hard to read, that's seems to be a good start. (click the link)

Now continue adding more functionality.
- Maybe put the board display in a function so you only need it once.
- Maybe put the game in a loop so you don't need 9 individual inputs.
- You could even test to see it a chosen position is already taken and display an error.

And if you need more help, please refer to my previous post

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

it is saying that "incompatible pointer conversion"

Oh goody, a guessing game! The odds: 1:139 chance of guessing the correct line.

See this and read it this time.

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

Use return 1; to indicate an error. return 0; indicates a successful execution.

All other values are not portable and may have no effect on many systems. I don't know if they'd be a problem, though.

On Windows, other values can be seen by the system and used. A batch file can get the exit status and process different code based on the value.

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

Yes we can. Problem is we're not all psychic so
1) we can't help you fix the code we can not see, nor
2) we can't answer questions that were not asked.

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

Correct me if I'm wrong, but crtl + x isn't z.

I find it interesting that when people are right, they say "Correct me if I'm wrong, "
but when they in fact are wrong, they write their information as if it was a fact. Just something I notice... :icon_wink:

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

Also, have you ever heard of SPACEs? Your blob-of-text format is very difficult to read. Take this blob:

int month,mth,yr,cen,day, year,dow;
  string name;
  getInput(month,day,year);
  mth=getMonthValue(month, year);
  yr=getYearValue(year);
  cen=getCenturyValue(year);
  dow=(day+mth+yr+cen)%7;
  switch(dow)
  { case 0: name="Sunday";break;
    case 1: name="Monday";break;

(where'd that space come from at day, year ) :icon_wink:
Reformatted so it's readable:

int  month, mth, yr, cen, day, year, dow;
  string name;
  
  getInput (month, day, year);
  
  mth = getMonthValue(month, year);
  yr  = getYearValue(year);
  cen = getCenturyValue(year);
  dow = (day + mth + yr + cen) % 7;
  
  switch(dow)
  { 
    case 0: 
      name = "Sunday";
      break;
    case 1: 
      name = "Monday";
      break;

Try it. You'll like it. And so will your instructor.

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

When I try to build this it tells me that "the subscript is not of integral type." It works when I try using int instead of double for linecount and arrayOne but the numbers in the .txt are floating point and I need to keep the decimals.

Subscripts need to be integers.
If you are counting lines, what use is a floating point number? Which line is 3.274? It's either line 3 or line 4.

The problem is that I have been trying to assign the values in the .txt file to the array for about 2 hours and I either get some crazy output, or an error of many kinds.

Without knowing what you've tried, can't help you fix it.

The thing is, I have to assign each individual line in the .txt to a different array,

Can you use an array or arrays? Like values[#lines][#valsPerLine] ?

I don't understand how to assign the numbers from the array at all

I'm sure you do. It involves an = sign.

let alone pick individual lines from a .txt file.

Use fgets() and read 1 entire line. Then you can use sscanf() to read each number out of that line.

I thought my description was fairly good...

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

getche() is a non-standard function and should not be used at all. They are trying to keep the program window open when you execute the code using the IDE. It's best to use a standard C function (like getchar() ) for that. return 0; is required because main() is an integer function. Any instructor that doesn't use return 0; is probably using void main() , which is wrong. Try not to take classes from these instructors -- they don't know the language well enough.

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

So what's the problem? What you have (with the bare description) looks OK so far.

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

Use while (!myInfile1.eof()) in place of line 35 and also close file handler at line 70) myInfile1.close();

No, don't. Here's why ( feof() is the same as .eof()

Xaviorin commented: Great resource with thorough explanation +1