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

Thanks for all the help so far, but I am a beginner and may have many more questions to come. How can I clear the screen (I knew my commands could make the program unusable on some computers without those, but I had no idea how to get around it.)

Don't. It's not necessary except in few cases, and it's not protable from system to system or compiler to compiler. Just output a few extra lines to separate output sections.

How do i create a string, and why not simply use a character array?

Instead of char varName[100]; use string varName; You can still access individula characters by varName[i]

Also on a somewhat different subject, I am 14 years old and would like to know if i am getting a headstart at all. Thanks again,Brent.tc at email removed

If you know a lot of 14 year olds programming C++, then no. I don't so I'd have to say yes...

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

Definitely cool. Although I expected it to keep going in further and show the Milky Way again... That woulda been neat!

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

Hello anyone if you see this please reply fast:
i need some major help with some programming and logic code through liberty basic, My project consist of making an ATM Program allowing the user to only enter the security code 3 times and it also prompts you to enter a number sequence to use the following options such as:withdrawal, deposit, check balance and exit and i can't use goto statements then it prompts you to enter the amount of money in your account and you can't withdrawl over that amount
thanks profess 69:eek:

OK, I'm replying as fast as I can. With the information you posted (plaese reread your post carefully) what can we say? You seem to have neglected to tell us what you need help with. Details are important.

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

thank you for your help, except I am not a very bright person, so maybe I did it wrong again, because when I run the program, it runs into an error and basically aborts...

You know, I just talked to my mechanic about my car. I told him "my car just did something wrong (error) and stopped (abort)". I'll give you one guess what his response was...

Please learn to explain your problem completely. Most of us aren't mind readers.

#include <stdio.h>
#include <string.h>

int main()
{
    char s[81] = {'\0'} ;
    printf("Enter the filename to open: ");
    FILE *fr = 0;    // this line must be before the executable
                     // statements, like printf
    fgets(s, 81, stdin);                 // read a line from the keyboard
    if ( fgets( s, 81, stdin ) != NULL ) // read another line 
    {                                    // and check for an error
      char *p = strchr( s, '\n' );
      if ( p ) *p = '\0';
      fr = fopen( s, "r" );
    }

    // if there was an error, read a line from an unopened file
    while ( fgets(s,81, fr) != NULL)
        fprintf(fr,"%s\n", s);

    fclose(fr);
    return 0;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you get the token 'A', that is the same as the number 65 (ASCII A == numeric value 65
In other words:

(char)'A' = (int) 65
(char)'B' = (int) 66
(char)'C' = (int) 67
(char)'D' = (int) 68
(char)'E' = (int) 69
etc.

(char)'a' = (int) 97
(char)'b' = (int) 98
(char)'c' = (int) 99
(char)'d' = (int) 100
(char)'e' = (int) 101
etc.

Therefore, if your token ch contains 'B' you can convert it easily to your 'variable' value of -2 with

var = -(ch - (int)'A');
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

is this better?

for ( int counter = 0; counter < SIZE; counter++ )

Yes. Now you have more loops. Check them, too.

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

And give us some idea what the errors are.

the error seems to be in the switch function..... but i'm not sure why it is not working

And how does this answer my question of what the errors are?

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

You have a problem understanding loops and arrays. You have

const int SIZE = 10;//size of array
...
    int array[ SIZE ];

Then your loop is defined as

for ( int counter = 0; counter <= SIZE; counter++ )

Array size is 10, you load 11 values and blow past your array. You have to make sure you never reference array or beyond.


As for your question, the first one. In the second code, all i represents is pass so it's a waste of space.

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

And give us some idea what the errors are.

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

normally do not pass the size of character arrays, which is the cause of many buffer overrun problems.

I'm not sure what you are saying here. My interpretation of what you said is you may have a buffer overrun because you passed the array size into the function. Seems to me that passing the size helps you prevent overruns. Bu not passing the size it's really easy to access elements outside the bounds of the array since you don't know where to stop.

Or are you saying "the cause of many buffer overrun problems is because programmers normally do not pass the size of character arrays."

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

Can I have both in at the same time?
This is going to be used on a unix and MS system.

Actually you don't want to clear the screen. It's bad form and it's not portable, as you can see. Best to just leave it.

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

HERE IS WHAT I HAVE SO FAR, THANKS SO MUCH!!

#include <iostream>
#include <string>
using namespace std; 
int main()
{
  int number;
  cout <<"Enter an integer to add: "; 
  cin>> number; 
  cin.ignore (1000,10);
  while (number != 0)
  { 
       std:: cout << "Enter an integer to add:";
       cin>> number; 
       cin.ignore (1000,10);
       while (number != 0)
        
   }
   std::cout << "Total. number: " << number;
  
  return 0; 
}

Assuming you want to learn what's wrong with your code and not just let someone else do your homework for you:

Where's the end of your first while?
What's the second while for?
Where are you adding the numbers entered to a total?
Where are your code tags so we can read your code? (see FAQ)

How about a bit of modifications:

A bit of modification? I hope you get a good grade on it...

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

It may be quite possible that the data rounded off is not used for calculations or used in calcultions which requires only the rounded off values. It could also be written to a file and used only for data analysis purposes, or maybe the OP had some other idea in his mind or maybe it was part of an assignment given at the college to test his coding skills, you never know.

True -- but with all the if...when...maybe's that get posted here (and you pointed out in this post), noone would get any answers because few would want to post a response based on all the if...when...maybe's to cover all bases. I will respond to what is directly posted and may make an educated guess as to the usage. If I guess wrong, then the OP obviously didn't communicate his problem/needs well enough. His fault, not mine.

:twisted:
So listen up, noobs! Post enough information that we don't have to guess at what you need to know. You need to tell us! That way us folks that are trying to help you pass your classes won't get into arguments like this one!
:p ;)

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

Pass in another string which will be loaded with the reversed string as you go through your return side of the function

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

I'm with bumsfeld on this one. You want as much precision as you can get throughout the program's calculations and only round for the display. You don't even want to round the number itself, just the display.

If you round prematurely, all your calculations will be slightly off. And the more calculations you do, the more inaccurate your answer.

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

Thanks for your reply too. I did write a program like u said. But i don't want it to take value beyond 100 i.e 101 or 102..... so that is reason i put them in the range.

So your first IF is at 100 and you output an error.

Thanks for your reply. How do I calculate for all the 5 students and store their individual score and then total it up outside the loop? I think i need to store them in some variable. There is where i get stuck and cannot proceed further.

What do you know about arrays?

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

You are somehow runing the function that adds the record twice. Could be that you have a couple ways to execute the function and because of the way your events are linked you run through the code twice.

I see this happen when you link an update via OnChange event on a TextBox for example, then when you change the box it executes the routine,which in turn updates the TextBox with a new value -- which kicks off the OnChange again.

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

You could set up another variable that increments each time your value wraps. That effectively gives you a 64bit counter. This of course would require some minor redesign every time your counter is accessed in the code.

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

You also don't need the range in the IF's. For example

IF score > 90   ; this will take everything above 90...
    Display A   ; Output grade and the IF is over
else
IF score > 80   ; this will take everything above 80...
    Display B   ; anything above 90 has already been taken care of above
else
...
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Quote "unless you know of other platforms besides the two I mentioned. If so, please inform the rest of us. "

Be informed

http://news.zdnet.co.uk/software/developer/0,39020387,39154054,00.htm

http://www.mono-project.com/Mono:About

regards

Although not an accurate answer (.NET is still only on Windows -- my point -- Mono is a clone and is not officially .NET. Picky but true), Mono looks like an interestig alternative. I find it curious that they have an Oberon compiler. Didn't know O had much of a following -- obviously it does.

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

boaland 5.5 and earlier have the same problem as VC++ 6.0 -- they are too old and do not support current C++ standards very well.

I guess I don't consider beig released in 2000 to be "too old" but I guess that's just me. Use what you like ad works for you.

'nuff said.

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

#1: Please stop bolding your messages. It isn't necessary.
#2: The code you posted (here with CODE tags, use them please) was:

#include <stdio.h>
#include <string.h>
main()
{
    char acbuffer[50];
     int icount=0;
     clrsrc();
     printf("Enter Any Word: ");
     scanf("%s", &acbuffer);
     strlen(acbuffer);
     for (icount=strlen(acbuffer); icount>0; icount--)
     {
          printf("%s\n", acbuffer);
          acbuffer[icount]='0'; 
     }
     getche();}

As niek_e said your '0' should be '\0'. That's almost all you need to fix.
There's one more thing but I'll let you figure that one out.

#3) main() is an integer function, therefore it must be specified as

int main()
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why stick to Borland ???

Why not? There's nothing wrong with the Borland compiler. It's when a bad compiler is in use you should change. But when you get right down to it, for the most part if it does the job, any compiler will do.

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

Depends on what you want to do. If it's just more of the same, as long as you didn't use non-standard Borland functions, your old code should compile fine.

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

Borland 4.5 is a 16 bit compiler. Upgrade to Borland 5.5 for 32 bit.

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

Evil Dead 2

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

cartoons (from back in the day) --> Warner Brothers

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

I detect just a little .NET hostility here. I guess you must be one of the members of the "lets all hate Microsoft club". Thats a rather tiresome debate that has been running for years and will probably do so for many more to come and is something I shall leave to others.

You have a very odd way of interpreting my response to your question. All I said is there are many platforms (O/S). And the only ones that can handle .NET are Windows XP and 2000. Please reread my posts and stop lookig for hostility towards M$. You stated one side. For completeness I stated another. You asked a followup question, I answered it, which was .NET has limited platforms available. C/C++ is on many more platforms, as well as PHP. I answered your question without errors -- unless you know of other platforms besides the two I mentioned. If so, please inform the rest of us.

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

If you need to write sort code, I would recommend insertion sort.
Read this:
http://www.eternallyconfuzzled.com/tuts/sorting.html

Not me. I'd use a bubble sort. The list is short. The sort is easy. Start with the easiest and when comfortable, move up to the harder ones.

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

How can I get a program to find and extract an email adress from a line and replaces the @ sign with 'AT'?

1) Search for the @
2) test characters after the @ for valid domain name construct. Memorize the first position that doesn't fit.
3) test the characters before the @ for valid email name construct. Memorize the first position that doesn't fit.
4) Copy all the characters between the memorized positions.

I just started learning c++ and have run into a wall. I can get my screen to display everyhing from the @ sign to the end of the string, but I cant get it to stop at the.com or the space right after.

Why not? What are you doing wrong?

I just need to see a solution or possible a different aproach, thanks!

Actually, what you need is to show us what you are doing and maybe we can help you fix it.

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

Legend

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

Yea I wouldn't be surprised. I'm using a DOS version of Borland C++. It doesnt even require installation just copying!!!

I'll take on Inanna's advice and try to get a new vrsion

So am I, version 5.5, and it does require some minor installation. Here's how I do it

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

Easier to ask what platforms can.

Windows XP & I believe Windows 2000.

You are a politicion - You answer a question by posing a different question and not answering the original question

Excuse me? I answered the reverse of the question which, using the commutative property of mathmatics, answers the original question. So I must be a mathematician. Either that or list 200+ platforms that can't handle .NET -- which I would argue does not answer the question because no one would be able to accurately list them all. I therefore chose to list all that could instead, implying none of the others could.

If you have a problem with that, please explain why.

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

Yeah, We aren't going to do your work for you.....

Speak for yourself :twisted:


sorry, couldn't resist....

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

Just curious to know what platforms are not capable of installing the .NET framework?

Easier to ask what platforms can.

Windows XP & I believe Windows 2000.

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

So what type of code would I have to write to make this work?

C or C++ might be a start. I can't believe this is your first program in the class so you should be able to do at least part of it. Then when you post something that shows an honest effort, we can help you further.

Plus we don't kow what you have learned so don't know whether vectors or arrays are useful to you. So you need to give us a little info.

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

Take a look at function fscanf() that delimits on whitespaces. Nothing wrong with using it in C++, it is part of ANSI C++.

Nothing wrong with it but totally unnecessary. cin is just C++'s version of scanf() . And there is no reason to read from a file using fscanf() .

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

Ok been working on this thing for quite some time now this is what I have came up with from the input you all gave me and thank you for the help by the way.

...

That is what I have came up with from taking what you all told me and getting some examples from the book, but I am still getting a butt load of errors.

Doesn't surprise me.

#include "stdafx.h"    //// What's this statement do for you?  Remove it. You don't need it.

// What type of function is this?  void, int, double?  Define it
ProductSales::ProductSales( string name )
{
    setProductName( name );
    aCount = 0;
    bCount = 0;
    cCount = 0;
    dCount = 0;
    eCount = 0;
}

//// What do these statements mean?  
//// INT is not a valid statement all by itself.  
//// Neither is "( A == $2.98 )"
    int; ( A == $2.98 );
    int; ( B == $4.50 );
    int; ( C == $9.98 );
    int; ( D == $4.49 );
    int ( E == $6.87 );


//// What function is this execuatable code in?
do
{
    cout << "What product sold A-E" << endl;
    cout << "How many sold of each" << endl;
    while ( product != -1 ) //end of file char
    {
        ...
    }
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yea all 3 files are in the same directory.
this is the code that DID work:

#include "e:\study\c\header.h"

Then you have a problem with your installation or the way your project was set up. You shouldn't need to specify the path using the d-quote form of the #include

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

i want the whole project fully finished do u ahve one where u could send me one

How much time will you give me to develop it? Are your specification complete enough for me to quickly code the project? How much is your grade worth to you? It's going to cost a bundle.

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

Or you could stay away from .NET so you have cross platform compatability and go with C++, C, Pascal, even Real Basic.

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

In general, you have to read all three colums, and just igore the first 2.

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

Where did you take the total sold and calculate the total price? Shouldn't that be in each case statement?

Also, at the beginning of your do loop, you should ask only 2 questions:
1) What product was sold (A-E):
2) How many sold:
The your switch value would be the product and the case calculates the total.

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

You have included header.h twice (In both files). Use some sort code like of this (might be C++, sorry)

#ifndef HEADER
#define HEADER
#include "header.h"
#endif

But I dunno wether that is the real problem

I don't see that problem at all. There is only one include in each .c file. And that would not cause a "can't find" error, that causes 'multiple definition' error.

Are you sure the files are all in the same directory? The " form of the include first looks in the current directory so the file should be found without a problem.

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

Have you been able to get the timer at least working? If so you're almost there. If not, simply make a quick program to understand how the timer works and use a text box to increment and display a count of each time the timer kicks off.

Then just use that timer to count the value down from your starting time. You can use the timer.enable property to start ad stop the timer for time-outs.

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

So, how do I get the length of a string in C++?

stringvariable.length()

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

its easy to use fputs for the char item[50] but still struggling with int cust_num (conversion) i'll appreciate any help !

Where did this conversion come in? I thought you were reading each line and replacing , with ;. There should be no conversions anywhere.

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

0 doesn't represent a digit.

Well thats news to me :cheesy: (maybe you wanted to say that 0 doesnt represent true condition )

I'm with Inana here. 0 does not represent a digit, it represents a binary 0. '0' represents a digit. A digit is an ASCII character, therefore it's '0' thru '9'.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
else
    {
        letter=letter-32;
        for(letter='A'; letter<96 || letter>122; letter++)
        {

Your for statement just destroyed the letter you typed in.

Also, it would be better to use getchar() instead of scanf() to read in a character. getchar() is designed to read a char whereas scanf() has to process the "%c" to find out you want to read a character then do what getchar() already does.

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

Actually Mr. WaltP did not direct his comment to you.

True. Thank you Mr. SOS for clearing that up in my absense. :)