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:
ASSIGNMENT:
Write a C++ program that performs following and formatted
results:
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
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:
I did a program in computer science c++. It worked fine the first and second time...
#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 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 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 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 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 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 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: 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 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 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>...