Conditions in class member functions
Feb 27, 2015 at 12:16am UTC
Hello, if someone could aid in my project that would be wonderful. I have the core program down, it runs fine and whatnot. However, my conditions inside my class member functions do not operate whatesoever.
Example, if cin >> vehicleID doesn't satisfy my condition (must be only three digits)it should proceed to ask for the vehicleID until it is three digits.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#include <iostream>
#include<conio.h>
using namespace std;
class UsedCar
{
private :
int vehicleID;
double price;
int year;
int miles;
int yearsOld;
double value;
public :
void determineMileageRating();
void setVehicleID();
void setPrice();
void displayUsedCar();
void setYear(int year);
void setMiles();
};
void UsedCar::setVehicleID()
{
cout << "Enter vehicle ID - use 3 digits " ;
cin >> vehicleID;
while (vehicleID < 99 && vehicleID > 1000)
{
cout << "Use 3 digits please " ;
cin >> vehicleID;
}
}
void UsedCar::setPrice()
{
cout << "Enter price " ;
cin >> price;
}
void UsedCar::setYear(int year)
{
cout << "Enter year of car " ;
cin >> year;
while (year < 1940 && year > 2015)
{
cout << "Check the year and reenter " ;
cin >> year;
}
}
void UsedCar::setMiles()
{
cout << "Enter miles on vehicle " ;
cin >> miles;
determineMileageRating();
}
void UsedCar::determineMileageRating()
{
yearsOld = 2015 - year;
cout << "------------------------------------" << endl;
if (miles < (yearsOld * 8000)){
cout << "This is a low mileage car" ;
}
else if (miles < (yearsOld * 15000)){
cout << "This is an average mileage car" ;
}
else cout << "That is a lot of miles for the age" ;
cout << endl;
}
void UsedCar::displayUsedCar()
{
cout << "You're vehichle information is as follows " <<
"\nID #" << vehicleID << "\nPrice: $" << price <<
"\nMiles: " << miles << endl;
}
void main()
{
UsedCar aCar;
aCar.setVehicleID();
aCar.setPrice();
aCar.setYear();
aCar.setMiles();
aCar.displayUsedCar();
_getch();
}
Thank you for your time and concern,
Tyler
Feb 27, 2015 at 1:05am UTC
A number cannot be both (less than 99) AND (greater than 1000).
Hope this helps.
Feb 27, 2015 at 1:36am UTC
Wow, VERY silly error!
Thank you so much.. I need to be more observant I guess.
Simple replace with || :)
Have a great night
Feb 27, 2015 at 6:10pm UTC
No problem. It happens to everyone.
Topic archived. No new replies allowed.