Question

I did a program in computer science c++. It worked fine the first and second time...

I did a program in computer science c++. It worked fine the first and second time when I ran the program, but suddenly it gave me an error. Then, after a few minutes, it started to run again and then the error showed up again. This is due tonight but I do not know what is wrong with it. PLEASE HELP ME! Also, the instruction for the assignment, the code, and the error that occurred in the program are below.

INSTRUCTIONS:

Plan your program before starting. Point distribution is as follows:

  1. Clean coding, "Logical Logic" and appropriate (not every line) commenting of the code: 20 points
  2. User's ease of use of the program e.g. Instructions for the program, data input requests during execution of the program in a manner that makes the user easily understand what kind of data they need to enter etc. : 20 points
  3. Accuracy of calculations and use of appropriate C++ functions/control structure statements: 20 points
  4. Display of data at the end of the program after calculation - presentation: 30 points

ASSIGNMENT:

Write a C++ program that performs following and formatted results:

  1. The output should show heading of Travel and Mileage Program.
  2. Users should be able to enter one car type and details about the car - programmer should decide what details are appropriate based on the discussion in the class (out of four possible cars that your program can do calculations for).
  3. Users should be able to input Travel Start and End destinations.
  4. Users should be able to enter the total distance in miles between the start and end destination.
  5. Based on the user's input, display following:
    1. Appropriate heading for the program with formatting using setfill().
    2. Display travel start and end destinations, Total distance to be traveled in miles and kilometers and other details for the vehicle to be used for the travel in more than one columns using setw().
    3. Display Total Gallons of fuel required to travel from start to end destination based on the data you researched about the four cars using control structure (if/else/else if) statements from C++. Formula for calculation is: Gallons of Fuel Required = Vehicle_Milage_Per_Gallon X Total_Number_of Miles

USE YOUR IMAGINATION AND CREATIVITY TO DISPLAY THE DATA IN PRESENTABLE, READABLE AND USEFUL MANNER!!

THE CODE:

#include <iostream>
#include <iomanip>
#include <string>
//Name space for I/O
using namespace std;

int main() {
string cType, cDes,start,end;
int distance;
float gallon, fReq;

cout << setfill('*') << setw(70) << " WELCOME TO TRAVEL AND MILEAGE ";
cout << setw(50) << setfill('*') << " " << endl;

cout <<setfill(' ') << setw(50)<<"Enter the car type : ";
getline(cin, cType);
  
cout <<setfill(' ') << setw(50) <<"Enter the car description : ";
getline(cin, cDes);

cout <<setfill(' ') << setw(50) << "Enter the starting location : ";
getline(cin, start);

cout <<setfill(' ') << setw(50) << "Enter the destination : ";
getline(cin, end);

cout << setfill(' ') << setw(50) << "Enter the distance in miles : ";
cin >> distance;

if (cType == "Ford escape") {
gallon = 2.831 * 18;
fReq = gallon * distance;
}
else if (cType == "Mazda6 I") {
gallon = 2.831 * 20;
fReq = gallon * distance;
}
else if (cType == "Nissan altima") {
gallon = 2.831 * 23;
fReq = gallon * distance;
}
else if (cType == "Honda accord") {
gallon = 2.831 * 24;
fReq = gallon * distance;
}
else {
cout << "Wrong entry";
}

cout <<endl<<endl<<setfill(' ') << setw(10) << "Car Type ";
cout <<setfill(' ') << setw(30) << "Car Desription ";
cout << setfill(' ') << setw(20) << "Start ";
cout << setfill(' ') << setw(20) << "Destination ";
cout << setfill(' ') << setw(10) << "Distance ";
cout << setfill(' ') << setw(10) << "FuelRequired "<<endl;
cout << setfill(' ') << setw(10) << "---------- ";
cout << setfill(' ') << setw(30) << "---------------- ";
cout << setfill(' ') << setw(20) << "------- ";
cout << setfill(' ') << setw(20) << "------------- ";
cout << setfill(' ') << setw(10) << "--------- ";
cout << setfill(' ') << setw(10) << "-------------- " << endl;
cout << setfill(' ') << setw(10) << cType;
cout << setfill(' ') << setw(40) << cDes;
cout << setfill(' ') << setw(15) << start;
cout << setfill(' ') << setw(15) << end;
cout << setfill(' ') << setw(10) << distance;
cout << setfill(' ') << setw(10) << fReq << endl;
return 0;

}

THE ERROR:

Traceback (most recent call last):
  File "/opt/online_gdb/www/ogdb_gui/ogdb/main/../pcompile.py", line 155, in <module>
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
OSError: [Errno 5] Input/output error
0 0
Add a comment Improve this question Transcribed image text
Answer #1

There is nothing wrong with your code... It happens some time with "GDB online Debugger"... Execute the current program with "Interactive Console" option set.

C++ Program:

#include <iostream>
#include <iomanip>
#include <string>
//Name space for I/O
using namespace std;
int main() {
string cType, cDes,start,end;
int distance;
float gallon, fReq;

cout << setfill('*') << setw(70) << " WELCOME TO TRAVEL AND MILEAGE ";
cout << setw(50) << setfill('*') << " " << endl;

cout <<setfill(' ') << setw(50)<<"Enter the car type : ";
getline(cin, cType);
  
cout <<setfill(' ') << setw(50) <<"Enter the car description : ";
getline(cin, cDes);

cout <<setfill(' ') << setw(50) << "Enter the starting location : ";
getline(cin, start);

cout <<setfill(' ') << setw(50) << "Enter the destination : ";
getline(cin, end);

cout << setfill(' ') << setw(50) << "Enter the distance in miles : ";
cin >> distance;

if (cType == "Ford escape") {
gallon = 2.831 * 18;
fReq = gallon * distance;
}
else if (cType == "Mazda6 I") {
gallon = 2.831 * 20;
fReq = gallon * distance;
}
else if (cType == "Nissan altima") {
gallon = 2.831 * 23;
fReq = gallon * distance;
}
else if (cType == "Honda accord") {
gallon = 2.831 * 24;
fReq = gallon * distance;
}
else {
cout << "Wrong entry";
}

cout <<endl<<endl<<setfill(' ') << setw(10) << "Car Type ";
cout <<setfill(' ') << setw(30) << "Car Desription ";
cout << setfill(' ') << setw(20) << "Start ";
cout << setfill(' ') << setw(20) << "Destination ";
cout << setfill(' ') << setw(10) << "Distance ";
cout << setfill(' ') << setw(10) << "FuelRequired "<<endl;
cout << setfill(' ') << setw(10) << "---------- ";
cout << setfill(' ') << setw(30) << "---------------- ";
cout << setfill(' ') << setw(20) << "------- ";
cout << setfill(' ') << setw(20) << "------------- ";
cout << setfill(' ') << setw(10) << "--------- ";
cout << setfill(' ') << setw(10) << "-------------- " << endl;
cout << setfill(' ') << setw(10) << cType;
cout << setfill(' ') << setw(30) << cDes;
cout << setfill(' ') << setw(15) << start;
cout << setfill(' ') << setw(15) << end;
cout << setfill(' ') << setw(10) << distance;
cout << setfill(' ') << setw(10) << fReq << endl;
return 0;
}

_____________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
I did a program in computer science c++. It worked fine the first and second time...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • My program works fine with if else conditions but when it is not working when I...

    My program works fine with if else conditions but when it is not working when I try to implement it using a for loop. Can you fix my for loop and please show me how to do this using loops? I would appreciate if you could explain the loop that you are using. /* Programming Challenge: Shipping Charges The Fast Freight Shipping Company charges the following rates: Weight of Package (in Kilograms) Rate per 500 Miles Shipped 2 kg or...

  • please do the program in simple programming it is for my first c++ computer class i...

    please do the program in simple programming it is for my first c++ computer class i posted the example on pic 2,3 which is how this should be done Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus the first 50 minutes are free. Charges for...

  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • How can I make this compatible with older C++ compilers that DO NOT make use of...

    How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){     string seat, flight, book = "y";     int int_flight, p = 0, j = 0;     int seat_number,...

  • I've written this program in C++ to compare 2 pizzas using classes and it works fine....

    I've written this program in C++ to compare 2 pizzas using classes and it works fine. I need to convert it to java using both buffered reader and scanner and can't get either to work. //C++ driver class for Pizza program #include <iostream> #include <string> #include <algorithm> #include <iomanip> using std::cout; using std::cin; using std::string; using std::endl; using std::transform; using std::setprecision; using std::ios; using std::setiosflags; #include "Pizza.h" int main() {             char response = 'Y';             while (response == 'Y')...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

  • This is C++. The task is to convert the program to make use of fucntions, but...

    This is C++. The task is to convert the program to make use of fucntions, but I am am struggling to figure out how to do so. #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ];    char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ]; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID,...

  • i have two issues that i need help. 1- that in case three and two only...

    i have two issues that i need help. 1- that in case three and two only one line is being read from the file 2- my case 4 is not working correctly as it should as the output is only " Enter 1 for Trump, 2 for Warren:" #include <iostream> #include <cctype> // For the letter checking functions #include <fstream> // For file input #include <iomanip> // For setw #include <ctime> #include <cstdlib> // For exit and abs #include <errno.h>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT