Need help with this input output program to a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chedda
    New Member
    • Feb 2008
    • 4

    Need help with this input output program to a text file

    everytime i try to compile and run the program, on the compiler it states on line
    where it says ofstream outfile("c:\\Us ers\\Michael\\D esktop\\Statist ics.txt");#incl ude <iostream> that theres an error, why is that? someone help, i dont know if theres a logical error or just some other error, someone please help.....






    this is the program

    [code=cpp]
    #include <iostream>
    #include <fstream>
    using namespace std;

    //Program to compute statistics for how students did on exams

    int main()
    {
    int id, students;
    double rright, wrong, Tanswered, Omitted, Grade, Total;
    students = 0

    ofstream outfile("c:\\Us ers\\Michael\\D esktop\\Statist ics.txt");

    outfile.setf(io s::fixed,ios::f loatfield);
    outfile.precisi on(3);

    cout << "Enter ID, right and wrong answers followed by spaces on the same line and press enter: ";
    cin >> id >> rright >> wrong;
    while (id != -1)
    {
    Tanswered = rright + wrong
    Omitted = 50 - Tanswered
    Percent = rright / Tanswered
    Grade = rright * 2

    outfile << "ID " << id << endl;
    outfile << rright << " right " << wrong << " wrong" << endl;
    outfile << "Total answered " << Tanswered << endl;
    outfile << "Number omitted is " << Omitted << endl;
    outfile << "Grade is " << Grade << endl;

    if (rright > wrong)
    outfile << "More right than wrong" << endl;
    else
    outfile << "More wrong than right" << endl;

    outfile << "Correct answer pct. is " << Percent << endl;

    if (Omitted > 10)
    outfile << "10 or more Omitted" << endl;
    else
    outfile << "less than 10 omitted" << endl;

    if (Omitted == 50)
    outfile << "Nothing is omitted" << endl;
    if (Omitted == 1)
    outfile << "Almost all the questions are omitted" << endl;

    Students++
    cout << "Enter ID, right and wrong answers followed by spaces on the same line and press enter: ";
    cin >> id >> right >> wrong;
    }
    outfile << "There are " << Students << " in the class" << endl;

    outfile.close() ;
    return 0;
    }[/code]
    Last edited by sicarie; Feb 25 '08, 02:41 PM. Reason: Code tagsa re [code=cpp] and after your code [/code]. Please use them. They want to be used. They like to be used.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by Chedda
    everytime i try to compile and run the program, on the compiler it states on line
    where it says ofstream outfile("c:\\Us ers\\Michael\\D esktop\\Statist ics.txt");#incl ude <iostream> that theres an error, why is that? someone help, i dont know if theres a logical error or just some other error, someone please help.....






    this is the program


    #include <iostream>
    #include <fstream>
    using namespace std;

    //Program to compute statistics for how students did on exams

    int main()
    {
    int id, students;
    double rright, wrong, Tanswered, Omitted, Grade, Total;
    students = 0

    ofstream outfile("c:\\Us ers\\Michael\\D esktop\\Statist ics.txt");

    outfile.setf(io s::fixed,ios::f loatfield);
    outfile.precisi on(3);

    cout << "Enter ID, right and wrong answers followed by spaces on the same line and press enter: ";
    cin >> id >> rright >> wrong;
    while (id != -1)
    {
    Tanswered = rright + wrong
    Omitted = 50 - Tanswered
    Percent = rright / Tanswered
    Grade = rright * 2

    outfile << "ID " << id << endl;
    outfile << rright << " right " << wrong << " wrong" << endl;
    outfile << "Total answered " << Tanswered << endl;
    outfile << "Number omitted is " << Omitted << endl;
    outfile << "Grade is " << Grade << endl;

    if (rright > wrong)
    outfile << "More right than wrong" << endl;
    else
    outfile << "More wrong than right" << endl;

    outfile << "Correct answer pct. is " << Percent << endl;

    if (Omitted > 10)
    outfile << "10 or more Omitted" << endl;
    else
    outfile << "less than 10 omitted" << endl;

    if (Omitted == 50)
    outfile << "Nothing is omitted" << endl;
    if (Omitted == 1)
    outfile << "Almost all the questions are omitted" << endl;

    Students++
    cout << "Enter ID, right and wrong answers followed by spaces on the same line and press enter: ";
    cin >> id >> right >> wrong;
    }
    outfile << "There are " << Students << " in the class" << endl;

    outfile.close() ;
    return 0;
    }
    Can you explain the error u are getting or atleast paste the error you are getting ?

    Raghuram

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Statements are missing semi-colons and some variables are not defined.

      Comment

      Working...