IntelliSense errors?

I am working on a project that calculates the fare for a ferry. I have started, not even close to finishing, when I started encountering this error...

This is my code currently:

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
// Assignment #3: Ferry Fare Calculation
// Written by: Katie
// Date: 29 January 2014
// Sources: http://cplusplus.com

#include <iostream> // normal header function
#include <iomanip> // necessary for setprecision function
#include <cmath> // necessaey for mathematical functions
using namespace std; // necessary for omitting std::cout, std::cin, etc.

const double REGULAR_FARE = 13.15
const double SENIOR_FARE = 6.55
const double YOUTH_FARE = 10.55
const double BICYCLE_CHARGE = 4.00
const double VEHICLE_W_DRIVER = 51.20
const double VEHICLE_W_SENIOR = 44.60
const double OVERSIZE_CHARGE = 51.20
const double VEHICLE_SIZE_A = 76.80
const double VEHICLE_SIZE_B = 153.60
const double VEHICLE_SIZE_C = 204.80

int main()
{
	string seniorStatus;
	string drivingVehicleOntoFerry;
	string oversizeVehicle;
	int passengers;
	int vehicleOnFerry;
	int regularFare;
	int seniorFare;
	int youthFare;
	int vehicleLength;
	double totalFare;

	cout << "Welcome to Katie's Fare Calculator" << endl;
	cout << "Are you driving a vehicle onto the ferry? (y/n):" << endl;
	cin >> drivingVehicleOntoFerry;
	cout << "Is the driver a senior citizen(65 or older) or disabled? (y/n):" << endl;
	cin >> seniorstatus;
	cout << "How many passengers in your vehicle? (excluding the driver)" << endl;
	cin >> passengers;
	cout << "How many regular fare adults in your group?" << endl;
	cin >> regularFare;
	cout << "How many senior citizens (65 years or older), or disabled persons in your group?" << endl;
	cin >> seniorFare;
	cout << "How many youth (6 - 18 years old) are in your group?" << endl;
	cin >> youthFare;
	cout << "Is your vehicle over 7 feet, 6 inches in height? (y/n):" << endl;
	cin >> oversizeVehicle;
	cout << "How long is your vehicle in feet?" << endl;
	cin >> vehicleLength;
}


I get errors starting at line 12:
Error 2 error C2059: syntax error : 'const'
Error 1 error C2143: syntax error : missing ';' before 'const'
IntelliSense: expected a ';


Line 23:
Error 3 error C2143: syntax error : missing ';' before '{'
Error 4 error C2447: '{' : missing function header (old-style formal list?)


Lines 45-51:
IntelliSense: expected a ';'
IntelliSense: this declaration has no storage class or type specifier


Line 52:
IntelliSense: expected a declaration


What is going on? These errors make no sense to me. However, I still have a lot to learn.

It should be noted that around those lines (45-51...) the program attempted to input tabs when pressing Enter to go to the next line. Is something "corrupted" somehow?

I am using MS Visual Studio for Desktop 2013 on a Windows 7 machine. I did try restarting Visual Studio and starting a new project using the same code I had pasted into Notepad in interim and I get the same errors.
You are missing semicolons after all your constants. Try fixing that and see what happens.
Oh goodness! Thanks for that. Added them and now have these errors:

Line 37:
Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

IntelliSense: no operator ">>" matches these operands
operand types are: std::istream >> std::string


Line 39:
Error 2 error C2065: 'seniorstatus' : undeclared identifier

IntelliSense: identifier "seniorstatus" is undefined


Line 49:
Error 3 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

IntelliSense: no operator ">>" matches these operands
operand types are: std::istream >> std::string
If you plan to use `std::string' then #include <string>

Also, cASe senSItIVe
Last edited on
Thanks for your replies, everyone. I've taken your suggestions & I've finished writing my code for the most part and now have new errors that I can't pin point.

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
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

double REGULAR_FARE = 13.15;
double SENIOR_FARE = 6.55;
double YOUTH_FARE = 10.55;
double BICYCLE_CHARGE = 4.00;
double VEHICLE_W_DRIVER = 51.20;
double VEHICLE_W_SENIOR = 44.60;
double OVERSIZE_CHARGE = 51.20;
double VEHICLE_SIZE_A = 76.80;
double VEHICLE_SIZE_B = 153.60;
double VEHICLE_SIZE_C = 204.80;

int main()
{
	std::string seniorstatus;
	std::string drivingvehicleontoferry;
	std::string oversizevehicle;
	int vehiclelength;
	int regularfare;
	int seniorfare;
	int youthfare;
	int vehicleonferry;
	int seniordriver;
	int passengerfare;
	int driverfare;
	int overheight;
	int oversize;
	double totalfare;

	cout << "Welcome to Katie's Fare Calculator" << endl;
	cout << "Are you driving a vehicle onto the ferry? (y/n):" << endl;
	cin >> drivingvehicleontoferry;
	cout << "Is the driver a senior citizen(65 or older) or disabled? (y/n):" << endl;
	cin >> seniorstatus;
	cout << "How many passengers in your vehicle? (excluding the driver)" << endl;
	cout << "How many regular fare adults in your group?" << endl;
	cin >> regularfare;
	cout << "How many senior citizens (65 years or older), or disabled persons in your group?" << endl;
	cin >> seniorfare;
	cout << "How many youth (6 - 18 years old) are in your group?" << endl;
	cin >> youthfare;
	cout << "Is your vehicle over 7 feet, 6 inches in height? (y/n):" << endl;
	cin >> oversizevehicle;
	cout << "How long is your vehicle in feet?" << endl;
	cin >> vehiclelength;

	if (drivingvehicleontoferry == "y")
		vehicleonferry = 1;
	else
		vehicleonferry = 0;

	if (seniorstatus == "y")
		seniordriver = VEHICLE_W_SENIOR;
	else
		seniordriver = VEHICLE_W_DRIVER;

	if (oversizevehicle == "y")
		overheight = OVERSIZE_CHARGE;
	else
		overheight = 0;

	passengerfare = ((regularfare * REGULAR_FARE) + (seniorfare * SENIOR_FARE) + (youthfare * YOUTH_FARE));
	driverfare = ((vehicleonferry * seniorstatus) + overheight);

	if (vehiclelength >= 20 | <= 39.9);
	driverfare = 0;

	if (vehiclelength >= 20 | <= 40);
		if (oversizevehicle == "n");
			oversize = VEHICLE_SIZE_A;
		if (oversizevehicle == "y");
			oversize = VEHICLE_SIZE_B;
		if (vehiclelength >= 30 | <= 39.9);
			oversize = VEHICLE_SIZE_C;
		if (vehiclelength >= 40);
			oversize = null;

	totalfare = ((driverfare + passengerfare) + oversize);

	cout << "Your total fare is: " << totalfare << "Katie's Fare Calculator" << endl;
}


This results in the following errors (note some lines are listed twice):

Lines 63, 65, 68, 72, 73, 80, 82, 84:
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data


Line 73:
error C2677: binary '*' : no global operator found which takes type 'std::string' (or there is no acceptable conversion)

IntelliSense: no operator "*" matches these operands
operand types are: int * std::string


Line 75, 78, 83:
Error 6 error C2059: syntax error : '<='
IntelliSense: expected an expression


Line 80, 82:
warning C4390: ';' : empty controlled statement found; is this the intent?


I tried replacing std::string with char and got different errors.

Also, regarding line 86, I know this 'null' will result in error. I need to code it so that it responds with simply prohibited if someone enters a length over 40' and I just haven't looked up how to do that yet.

If it helps you to better understand what I'm attempting here, this is the data for the fares to work with:
Passenger Fares (and Bicycle Surcharge)
Adult (age 19 – 64): $13.15
Senior / Disabled (age 65 and over): $6.55
Youth (age 6 – 18): $10.55
Bicycle Surcharge Only: $4.00
Vehicle & Driver Fares for vehicles under 20' (includes the driver)
Vehicle Under 20’ and Driver: $51.20
Vehicle Under 20’ and Senior/Disabled Driver: $44.60
Over 7'6'' Height Surcharge: $51.20
Vehicle Length Based Fares (includes the driver)
20’ to under 30' Under 7'6" High: $76.80
20’ to under 30' Over 7'6" High: $153.60
30’ to under 40': $204.80
40’ and up: Prohibited

The questions asked in the program are the ones I must use, I cannot modify them.
> no operator "*" matches these operands
> operand types are: int * std::string
yeah, one of the fails of c++
8*"na" + " batman"

> I tried replacing std::string with char and got different errors.
¿genetic programming?

1
2
3
4
5
//driverfare = ((vehicleonferry * seniorstatus) + overheight);
if( seniorstatus == "foo" )
   driverfare = vehicleonferry * 3.14 + overheight;
else
   driverfare = vehicleonferry * 2.72 + overheight;



1
2
//if (vehiclelength >= 20 | <= 39.9);
if( vehiclelength >= 20 or vehiclelength <= 39.9) //but it is a tautology 
also note the semicolon at the end. That is the body of the `if', that would be the statement (empty)
Last edited on
Sorry, I don't think I quite understand all of your feedback.

Are you saying that "*" cannot be used in C++?? I thought I've used this command before for multiplication?

Are you saying that the semicolon is necessary or not necessary after the if statement?

My thinking for using the if (vehiclelength >= 20 | <= 39.9); code twice is because there are four different scenarios for these "oversized" vehicles I am trying to accommodate for. If the vehicle is over 7'6" in height but under 20' in length there is a surcharge. If it is over 20' in length and under 7'6" there is a specific fare, if it is 20'+ in length and over 7'6" tall there is another specific fare, and if it is 30'+ long there is another fare regardless of height. Is there a better way to approach this?
> Are you saying that "*" cannot be used in C++??
I'm saying that you can't multiply a number and an string.
Other languages allow it. By instance, in python 3*"ab" would result in "ababab"

The line in question (which is not 73, but 68)
1
2
3
driverfare = ((vehicleonferry * seniorstatus) + overheight);
//that could be interpreted as 
driverfare = 1*"n" + 51.20

¿what are you expecting to happen?


> Are you saying that the semicolon is necessary or not necessary after the if statement?
The syntax is if (condition) statement
an empty statement is a valid statement. So if you say
1
2
3
if( answer == 42 )
   ; //note the semicolon
delete this; //not part of the if, it would always execute 



> My thinking for using the if (vehiclelength >= 20 | <= 39.9)
that's invalid syntax. If what you wanted to say was `the length of the vehicle is between 20 and 40' [) then it would be
if( vehiclelength>=20 and vehiclelength < 40)
For line 73, I was thinking that in the case that the person has a car it would charge the appropriate vehicle with adult driver or senior driver fare. For example, If it was an adult drive it would multiply "1" by the "VEHICLE_W_DRIVER" const effectively applying the correct fare. But if, for example, the person was not driving a vehicle onto the ferry it would multiply "0" effectively eliminating any vehicle fare.

I just realized, however, I haven't accounted for what the fee would be if there was no vehicle at all.


Regarding semicolons, if I were to write this:
1
2
3
4
5
if (vehiclelength >= 20 and vehiclelength <= 39.9)
		if (oversizevehicle == "n")
			oversize = VEHICLE_SIZE_A;
		if (oversizevehicle == "y")
			oversize = VEHICLE_SIZE_B;

Then this is correct use of semicolons?
That would be read as
1
2
3
4
5
6
7
8
if (vehiclelength >= 20 and vehiclelength <= 39.9)
{//braces added for clarity
		if (oversizevehicle == "n")
			oversize = VEHICLE_SIZE_A;
}
//outside
		if (oversizevehicle == "y")
			oversize = VEHICLE_SIZE_B;
So, these need to be inside/outside of curly brackets??
Topic archived. No new replies allowed.