User Profile

Collapse

Profile Sidebar

Collapse
gonzo
gonzo
Last Activity: Nov 20 '06, 10:33 PM
Joined: Nov 2 '06
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • gonzo
    replied to Help a newbie sort strings from a file?
    in C
    D'oh! all I had to do was change the int[] to a string[]... What a pointless post.

    Admin, please feel free to delete this post.
    See more | Go to post

    Leave a comment:


  • gonzo
    replied to Help a newbie sort strings from a file?
    in C
    Wish I could've edited my first post. =/

    Anyways, I think I've figured out my main problem. Now can anyone tell me what I need to fix so that it doesn't output a load of random garbage characters everywhere? Here's the code, (it should compile and run fine):
    Code:
    #include <iostream>
    #include <fstream>
    #include <string> 
    
    using namespace std;
    
    void sort_LastName(
    ...
    See more | Go to post

    Leave a comment:


  • gonzo
    started a topic Help a newbie sort strings from a file?
    in C

    Help a newbie sort strings from a file?

    So I have a project where I'm supposed to have a .txt input file of no more than ten first names, last names and birth years, and than in a menu I'm to give the user some options as to how the strings can be sorted. My problem is kind of hard to understand, so please bear with me. I've figured out how to sort the last names, first names and birth years individually, but how do I make it so that all 3 things match up correctly so that the first names,...
    See more | Go to post

  • gonzo
    replied to Please help me get started!
    in C
    You just want to stick those 3 counts at the end in a cout statement so the program does what it's supposed to. This program below should compile and execute fine, but I suggest you look everything over so that it makes sense to you.


    Code:
    #include <iostream>
    
    using namespace std;
    
    void main()
    {
       int age;
       int count1 = 0;
       int count2 = 0;
       int count3
    ...
    See more | Go to post

    Leave a comment:


  • gonzo
    replied to Please help me get started!
    in C
    I forgot to add this, but It should be obvious once you get your program together and run it. You're going to want to add a " count1--; " after the loop to compensate for the -1 sentinel. Otherwise, it's going to say you have 1 extra person in age group one (17 and under)...
    See more | Go to post

    Leave a comment:


  • gonzo
    replied to Please help me get started!
    in C
    I'm not sure what you've learned so far, but here's how I'd go about it...

    Code:
    int age;
    int count1 = 0;
    int count2 = 0;
    int count3 = 0;
    
    do
    {
       cout << "Enter an age: ";
       cin >> age;
       
       if ( age <= 17 )
       {
             count1++;
       }
    
       else if ( age < 65 )
        {
    ...
    See more | Go to post

    Leave a comment:


  • gonzo
    replied to Please help me get started!
    in C
    I would make a while (or do-while) loop to keep taking ages until -1 is entered. I'd have 3 seperate counters for each age group. Make some If statements in the loop so each time an age is entered, 1 is added to that count. Hope that helps, and goodluck.

    do
    {
    cout << "Enter your age: ";
    cin >> age;
    .... and then all the other code
    } while (age != -1);
    See more | Go to post

    Leave a comment:


  • gonzo
    replied to Question about arrays and file input...
    in C
    Thanks for the reply. I couldn't quite figure out how to get pointers to work, so I went ahead and just assigned the array 11 elements, (I put 11 numbers in the .txt file). It will compile, but upon execution I get a run-time error saying "Stack around the variable 'Array' was corrupted." I'm not sure what that means. The program is kinda long (and probably reeks of a beginner), but if necessary I can post the code...
    See more | Go to post

    Leave a comment:


  • gonzo
    started a topic Question about arrays and file input...
    in C

    Question about arrays and file input...

    Say you have a .txt file with a random amount of numbers. Is there a way to initialize an array with that input file of numbers?

    After telling the program to open the input file, "inputFile, " I made an array called "Array[ ]" and tried to initialize it to the input file. It looks like this: "int Array[ ] = {inputFile};", but it obviously doesn't work. I get an error saying it cannot convert from 'std::ifstream'...
    See more | Go to post
No activity results to display
Show More
Working...