Can you find a bug in this program

Assignment Help C/C++ Programming
Reference no: EM13938177

Can you find a bug in this program and then fix it so that it won't have an infinite loop?

#include <iostream>
#include <fstream>

using namespace std;

void CalculateAvgScore(ifstream &fIn,ofstream &fOut);

int main(int argc, char *argv[])
{
ifstream fin;
ofstream fout;

char inFileName[20],outFileName[20];

cout << "Enter the name of an existing text file: ";
cin>>inFileName;

cout << "Enter a name for output text file: ";
cin>>outFileName;

fin.open(inFileName,fstream::in);//open the input file
fout.open(outFileName,fstream::out);//open the ouuput file

CalculateAvgScore(fin,fout);//add one more field avgscore to the output file

fin.close();//close the input file
fout.close();//close the output file

system ("PAUSE");
return 0;
}

void CalculateAvgScore(ifstream &fIn,ofstream &fOut)
{
while (!fIn.eof())
{
char firstName[30],lastName[30];
int Scores[10]={0};
int totalScore=0;
double avgScore=0;

fIn>>lastName;//read lasttname
fIn>>firstName;//read firstname

if (lastName[0]=='') continue;//skip empty lines

for (int i=0;i<10;i++)
{
fIn >> Scores[i];//read score one by one
totalScore += Scores[i];
}

avgScore = (double)totalScore / 10;//calculate avg score

fOut << lastName;//write lastname
fOut << " ";//write one space

fOut << firstName;//write firstname
fOut << " ";

for (int j=0;j<10;j++)
{
fOut << Scores[j];//write score one by one
fOut << " ";
}

fOut << avgScore;//write avg score
fOut << "n";//write one change line character
}
}

Attachment:- consuelo_charlton_assignment5.09.zip

Reference no: EM13938177

Questions Cloud

Analyse the threat or opportunity : Describe any biases that are relevant and need to be avoidedEvaluate the financial impacts of the decision (or of not making the decision) in terms of costs, revenue and/or service levels
Elements of a potential wbs : Q1: Level 1 WBS Elements With reference to the referenced example job drawings list at least 5 Level 1 Elements of a potential WBS. Q2: Level 2 WBS Headings Select 5 of the Level 1 Elements from Q1 and list potential Level 2 Headings under each. ..
Prepare the journal entry to record the purchase : Prepare the journal entry to record the purchase. By how much did this purchase increase or decrease the excess of current assets over current liabilities?
Investment where you receive a cashflow : Consider an investment where you receive a cashflow of +$400,000 per year for the first 5 years (times 1,2,3,4,5) and then $300,000 per year for the next 5 years (times 6-10), then $200,000 per year for the next 5 years (times 11-15) and then $100..
Can you find a bug in this program : Can you find a bug in this program and then fix it so that it won't have an infinite loop?
Understanding or analysing the knowledge situation : What are the possible models for understanding or analysing the knowledge situation. What is the knowledge or intellectual capital that needs to be managed or process
Why are vegetarians more efficient at saving energy : Why are vegetarians more efficient at saving energy and food resources? Would our food problems be solved if everyone chose a vegetarian diet? Why or why not?
What is each years working capital movement : Working capital values for accounts payable and inventory at the beginning of each year are to be calculated by applying the target working capital days to the appropriate forecast revenue and/or cost figures for the coming year.
Explain the network fundamental characteristics : Write a 1-2 page paper that includes the following based on your chosen Local Organization: Explain the network's fundamental characteristics and components. Click the Assignment Files tab to submit your assignment

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd