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

  Write a program that will be used to gather statistical data

Write a program that will be used to gather statistical data about the number of movies

  Application to accept the name of a folder

Therefore, she asks Hayley to modify the application to accept the name of a folder and display the following details of the files located in the folder: File name File size File creation date. Write the code that Hayley should write to create the..

  Writing a program that creates a linked list

Writing a program that creates a linked list from 100 randomly generated numbers and sorts the using a heap. One heap in ascending order and one heap in descending order. Then displays the original linked list and both sorted lists.

  Create the program which converts fahrenheit to celsius

Create the following program which converts Fahrenheit to Celsius. Your program must have the following functions: Read integer Fahrenheit temperatures from the user.

  Write a program that reads the scores from the file

Write a program that reads the scores from the file and displays their total and average. Scores are separated by blanks.

  Modify the code to change the variables

Quickly modify the code to change the variables if needed to the correct data type. Comment the code and indicate what the line or function performs

  Create a program that will input a group of floating point

Create a program that will input a group of floating point values, storing them as double values in an array. This array will then be sent to three functions.

  Computer-based training

Computer-based training is more widely used today by both organizations and educational institutions. Discuss the differences between CBT and eLearning in both environments.

  Write a script that creates a craps game

Write a script that creates a craps game and meets the following requirements. Name the script craps.sh The script will get 2 random numbers between 1-6.

  Write a for loop that displays the following set of numbers

Write a for loop that displays the following set of numbers 0, 5, 10, 15, 20, 25 ...... 500.

  Develop and implement an interactive two-player yahtzee game

Eliminate redundancy within a program by applying loops and functions - Create structure charts for a given problem and determine an appropriate functional decomposition or top-down design from a structure chart

  Write a c++ statement that outputs the data stored

Write a C++ statement that declares student to be a personType object, and initialize its first name to "Buddy" and last name to "Arora".

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