I am new (hence beginners). I am having issues with a program I am writing. Program: I have multiple questions to answer before getting to some calculations related to proposed ticket prices. I want to answer some questions with y/n (representing yes/no) responses and have found that I need to set type to char for these inputs. I also want to ask some questions that have integer or double type responses. While running the program, after entering top two char questions the program prints rest of questions without asking for inputs. Help! Losing sleep. ;)
//Purpose of this program: is to provide a way to calculate the fare of an //individual vehicle using the Anacortes to Friday Harbor Ferry.
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
//declare variables
int adultsMinusDriver = 0, youthsMinusDriver = 0, bikeRiders = 0, totalAdults = 0;
int driverAge = 0, seniors = 0, n = 0, y = 0, response = 0, vehicleHeight = 0;
double vehicleLength = 0, totalFare = 0,seniorsMinusDriver = 0, vehicleDriverFare = 0;
cout << "Welcome to Oliver's fare calculator! ";
//assuming driver is an adult? Can't someone between 16-18 drive onto the fairy?
cout << "Are you driving a vehicle onto the ferry? (y/n) : ";
cin >> response;
cout << endl;
cout << "Is the driver a senior citizen (65 or older), disabled? (y/n) : ";
cin >> driverAge;
cout << endl;
cout << "How many passengers are in your vehicle? (excluding the driver) ";
cout << endl;
cout << "Adults (age 19 - 64) : ";
cin >> adultsMinusDriver;
cout << endl;
cout << "Senior Citenzens (65 or older), or Disabled Persons: ";
cin >> seniorsMinusDriver;
cout<< endl;
cout << "Youth (age 5 - 18) : ";
cin >> youthsMinusDriver;
cout << endl;
cout << "Is your vehicle over 7 feet, 6 inches in height? (y/n) ";
cin >> vehicleHeight;
cout << endl;
cout << "How long is your vehicle in feet: ";
cin >> vehicleLength;
cout << endl;
cout << "How many people in your group are traveling with a bicycle? ";
cin >> bikeRiders;
cout << endl;
Huh, where is your logic. also, when asking for y or n, you should preferably use a char, or a static_cast will be needed to convert the int to a char.
Billy
My intention on the "how many passengers in vehicle" was to follow with allowing user to input #seniors, #adults, #youth separately.
The intention with the "seniors or disabled" together is that they cost the same price for admittance. Sorry, you wouldn't of seen this, I didn't post entire program.
Thanks!
Runner, I added char now. Thank you!
naaissus, are you suggesting I turn all variables to char, or just y/n questions? Thanks!
I seem to have it working though. Thank you all. Used the following:
If I would like the program to exit if n is entered for one of the y/n questions how would I make this happen? I tried exit(0); at the end of this code but this doesn't work. I also tried to place this statement just under the: cout << "Are you driving a vehicle onto the ferry? (y/n) : ";
cin >> response;
cout << "Welcome to Oliver's fare calculator! " << endl;
//assuming driver is an adult? Can't someone between 16-18 drive onto the fairy?
cout << "Are you driving a vehicle onto the ferry? (y/n) : ";
cin >> response;
cout << "Is the driver a senior citizen (65 or older), disabled? (y/n) : ";
cin >> driverInfo;
cout << endl;
cout << "How many passengers are in your vehicle? (excluding the driver) ";
cout << endl;
cout << "Adults (age 19 - 64) : ";
cin >> adultsMinusDriver;
cout << "Senior Citenzens (65 or older), or Disabled Persons: ";
cin >> seniorsMinusDriver;
cout << "Youth (age 5 - 18) : ";
cin >> youthsMinusDriver;
cout << "Is your vehicle over 7 feet, 6 inches in height? (y/n) ";
cin >> vehicleHeight;
cout << endl;
cout << "How long is your vehicle in feet: ";
cin >> vehicleLength;
cout << endl;
cout << "How many people in your group are traveling with a bicycle? ";
cin >> bikeRiders;
cout << endl;
if ( response = n )
exit(0);
else
cout << endl << endl;
Perfect. Thank you! I will do the code tags from now on.
Just as a side note. I am now in love with this forum. Thanks to all the people that participate. Maybe I could do the same someday (if I get good enough). For now I will soak up the help. Cheers.