Sie sind auf Seite 1von 3

/*

Timothy Hinh
PIC 10A Intro. to Progra
mming
ID: 604-456-658
Fall 2015
Email: timothyhinh79@gmail.com
Assignment #3
Section: sec# 4B
Honesty Pledge:
I, Timothy Hinh, pledge that this is my own independent
work, which conforms to the guidelines of academic honesty as
described in the course syllabus.
List of known bugs:
*/
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
stringstream output; // needed to store values from input and prices in
table format to be displayed at the end of program
string input; // this will be used repeatedly for every string input
string initials;
string costContinue;
bool properInput; // needed to set loops for when the user puts in bad i
nput for the transport/hotel or yes/no questions
int numTripsOrNights;
int initial = 0;
double prices; // this will be used repeatedly for every number input
double euroUSDConversion;
double total = 0; // initialization necessary for use in loops, stores t
otal value after every number input (prices) from user
output << fixed << setprecision(2);
output << "Summary of your trip\n"
<< "--------------------\n\n";
cout << "Name of the traveler: ";
getline(cin, input);
output << "Name: " << input << endl;
do {
initials += input.substr(initial, 1);
initial = input.find(" ", initial) + 1;
}
while (initial - 1 != string::npos); // This do-while loop takes
the initials of the user.
output << "Initials: " << initials << endl;
cout << "Date of departure: ";
getline(cin, input);
output << "Departure: " << input << endl;
cout << "Arrival: ";
getline(cin, input);
output << "Arriving: " << input << "\n\n";
cout << "Cost of the Euro / USD conversion: ";
cin >> euroUSDConversion;
cin.ignore();
output << "----------------------------\n\n";
output << left << setw(40) << "Object" << right << setw(20) << "Total EU

R" << setw(20) << "Total USD"


<< left << setw(40) << "------" << right << setw(20) << "--------" << setw(20) << "---------" << endl;
do {
cout << "Name the type of cost (must be either transport
or hotel): ";
do {
getline(cin, input);
if (input == "transport" || input == "Transport") {
properInput = true;
cout << "What kind of transportation are you usi
ng?\n";
getline(cin, input);
output << left << setw(40) << input;
cout << "Introduce the cost of this transportati
on: \n";
cin >> prices;
cin.ignore();
cout << "Will you only be making one trip with t
his type of transportation?\n";
getline(cin, input);
if (input == "no") {
cout << "How many trips do you plan to m
ake?\n";
cin >> numTripsOrNights;
prices *= numTripsOrNights;
cin.ignore();
}
else {
numTripsOrNights = 1;
prices *= numTripsOrNights;
}
total += prices;
output << right << setw(20) << prices << setw(20
) << prices * euroUSDConversion;
}
else if (input == "Hotel" || input == "hotel") {
properInput = true;
cout << "What is the name of the hotel you're st
aying at?\n";
getline(cin, input);
output << left << setw(40) << input;
cout << "What is the nightly price of this hotel
?\n";
cin >> prices;
cout << "How many nights do you plan on staying
in this hotel?\n";
cin >> numTripsOrNights;
cin.ignore();
prices *= numTripsOrNights;
total += prices;
output << right << setw(20) << prices << setw(20
) << prices * euroUSDConversion;
}
else {
cout << "Please enter either transport or hotel.
\n";
properInput = false;
}

} while (properInput == false);


cout << "Do you want to introduce any more costs?\n";
do {
getline(cin, costContinue);
if (costContinue == "Yes" || costContinue == "yes" || co
stContinue == "No" || costContinue == "no")
properInput = true;
else{
cout << "Please enter yes or no.\n";
properInput = false;
}
} while (properInput == false);
} while (costContinue == "yes" || costContinue == "Yes");
cout << endl;
output << "\n\n";
output << right << setw(60) << "---------" << setw(20) << "---------";
output << left << setw(40) << "TOTAL" << right << setw(20) << total << s
etw(20) << total * euroUSDConversion;
cout << output.str() << endl; // output.str() contains the entire table
summary of costs
return 0;
}

Das könnte Ihnen auch gefallen