Need a urgent help, Test in hours time!!

This is a discussion on Need a urgent help, Test in hours time!! within the C Programming forums, part of the General Programming Boards category; Someone please help me I'm having my exam tmrw! So nervous Im having trouble combining both the .txt files in ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Need a urgent help, Test in hours time!!

    Someone please help me I'm having my exam tmrw! So nervous
    Im having trouble combining both the .txt files in to 1 file and run the program which I have coded.

    I want the output of this program to be like:

    James 90
    Thomas 50
    Sheila 60
    Jessica 20
    Precillia 10
    2 out of 5 of the class has failed the test.

    ---

    I've attached the necessary files. here is my program;

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstring>
    
    using namespace std;
    
    int main()
    {
    string getcontent;
    ifstream openfile ("names.txt") ;
    if (openfile.is_open())
    {
    while(! openfile.eof())
    {
    openfile >> getcontent;
    cout << getcontent << endl;
    }
    }
    int marks[100];
    int x=0,fail=0, pass=0;
    
    
    fstream textfile;
    textfile.open("marks.txt");
    
    while(! textfile.eof()){
    textfile >> marks [x];
    
    if(marks[x]<50){
    fail++;
    }
    else{
    pass++;
    }
    x++;
    }
    
    textfile.close();
    openfile.close();
    cout << fail << " students out of "<< (fail+pass) << " did not pass.";
    
    return 0;
    }

    main.cppmarks.txtnames.txt

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,541
    FYI: You posted poorly C++ code in a C sub-forum.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Time between Military Hours
    By StarOrbs in forum C++ Programming
    Replies: 18
    Last Post: 03-01-2005, 05:46 PM
  2. Time to test your C++ abilities...
    By Darkman in forum C++ Programming
    Replies: 19
    Last Post: 01-10-2004, 08:58 AM
  3. Replies: 3
    Last Post: 06-13-2003, 06:47 AM
  4. URGENT!!!!9 hours left!!!
    By emiyca in forum C++ Programming
    Replies: 2
    Last Post: 10-29-2001, 07:34 AM
  5. Test of avatar - don't waste time reading this.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-10-2001, 05:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21