Thread: Need some help on a project

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    Need some help on a project

    Code:
    #include <iostream>
    #include <iomanip>
    #include<fstream>
    using namespace std;
    int main()
    {
      int grade, kount, average, max_score, min_score;
      kount = 0;
      ifstream inFile;
      inFile.open("i:\\programming\\grades.txt");
      inFile >> grade;
    
      while (!inFile.eof()) {
        if (grade >= 0 && grade <= 100)
          kount += 1;
    
        cout << "\n" << setw(10) << grade;
    
        if (grade < 0 || grade > 100)
          cout << "    Invalid \n";
    
        if (grade >= 0 && grade <= 59)
          cout << "    Unsatisfactory \n";
    
        if (grade >= 60 && grade <= 89)
          cout << "    Satisfactory \n";
    
        if (grade >= 90 && grade <= 100)
          cout << "    Outstanding \n\n";
    
        else
          cout << endl;
        inFile >> grade;
      }
    
      inFile.close();
      cout << "\n\n\n Hit enter to continue...";
      cin.get();
    
      return 0;
    }
    Write a program to read in a collection of exam scores ranging in value from 0 to 100. Your program should count and print the number of outstanding scores (90 - 100), the number of satisfactory scores (60 - 89), the number of unsatisfactory scores (0 - 59) and the number of invalid scores (less than 0 or greater than 100).
    It should display the average score (with 2 decimal digits), the highest score, the lowest score, and the category of every score. Do not include the invalid scores in the average, max, or min. You will need to create a data file named grades.txt.
    Can I get some help with this? Not exactly the whole answer (if you gave me that I wouldn't be mad though) but just something to put me in the right path.
    Last edited by Salem; 10-31-2011 at 10:03 AM. Reason: remove pointless tags

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    >>while (!inFile.eof())
    You do not want to use eof as loop control (there is a FAQ on the site as to why).
    Other than that, is there a specific problem you have in mind? You seem to have a basic skeleton, but not much more than that. Are you confused as how to approach these problems?
    At the moment, I can give you a push in the right direction: think about how you would do it in real life, and then write down the logical steps in the logical order on a piece of paper.
    If there are specific problems, feel free to ask.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    I thought fstream's eof() worked a different way than feof() in C since I never got the same problem as described in the FAQ. Never read anything about it; just thought.

    @OP:

    After using the if check for grade being >=0 and <= 100, there's no need to check again and say invalid. Just put an else at the end of your first if clause and then say Invalid. Also the else statement you have right now will always create a new line if the grade is less than 90 (which I don't understand the use of another line break if you already have cout << "\n";. Use brackets. Besides that, if you have any specific problems/errors/bugs, please describe them here and you'll get help.
    Last edited by Rodaxoleaux; 10-31-2011 at 02:30 PM. Reason: forgot to actually reply to the OP
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    Thank you guys for being so friendly and providing me with some support, I finished the program already. By the way I had to use the eof because the professor said we had to, oh well.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then you should point out to your professor that it's wrong.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes Project (Not class project)
    By adam.morin in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2011, 01:48 AM
  2. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  3. another c project
    By thenewbiecoder in forum C Programming
    Replies: 7
    Last Post: 07-08-2009, 04:15 AM
  4. Project
    By KRAZY380 in forum C++ Programming
    Replies: 3
    Last Post: 05-19-2002, 11:37 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM