Thread: help with my program for class, PLEASE!!!

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    3

    Red face help with my program for class, PLEASE!!!

    Hi, I am new to the forum. I am taking a CS class and this is our first program assignment and I am totally lost.

    We have to create a program that reads the following data from a disk: (it must skip the symbols & only print the numbers)

    @2,89#3,*67
    $187,3#%34,72#123#
    *3*7*1#*3,4,8

    Once program is read it must read as follows:
    289
    367
    1873
    3472
    123
    371
    348

    We cannot use extractions, we must used nested loops.
    I know how to read the info from disk but I am lost after that.

    Professor suggested using sum = 0; sum = sum + digit -- in loops. -- Please just tell me how my loop process should start.

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    Re: help with my program for class, PLEASE!!!

    Originally posted by acegillss
    Hi, I am new to the forum. I am taking a CS class and this is our first program assignment and I am totally lost.

    We have to create a program that reads the following data from a disk: (it must skip the symbols & only print the numbers)

    @2,89#3,*67
    $187,3#%34,72#123#
    *3*7*1#*3,4,8

    Once program is read it must read as follows:
    289
    367
    1873
    3472
    123
    371
    348

    We cannot use extractions, we must used nested loops.
    I know how to read the info from disk but I am lost after that.

    Professor suggested using sum = 0; sum = sum + digit -- in loops. -- Please just tell me how my loop process should start.
    1. This isn't much of an importance, but instead of sum = sum + digit, you should use sum += digit which does the same.

    For the loop, just use something like:
    Code:
    for(int i = 0; i < 3; i++){
      while(sum == 0){
          [code to read data];
          sum += 1;
      }
    }

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    dont know if this is much help or not but you it looks like you will end one loop for a given number evertime you encounter a # symbol.

    Ignore everything else and extract/calculate the number from the remaining digits.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    well if he wants you to read in stuff from a file then i am going to assume that it is a text file.

    numbers as text have an ASCII value of 48 - 58. if its a text file you are reading them as characters anyway, so

    char ch;
    // get a char from the file
    if ( ch < 48 || ch >58 )

    that will exclude anything thats not a number. then you read those until you hit what determines the end of a number ( as curlious said, perhaps pound and newline ). then just string them together and print them. you could do the whole thing without using any math at all.
    I came up with a cool phrase to put down here, but i forgot it...

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    or you can use c-style strings... use isdigit();
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM