Code not working and I'm unsure why

My code isnt working and I dont know why. Error messages on lines 9, 11, 15, 20, 21, and 21.

Code:


1 #include <iostream>
2 #include <string>
3
4
5 using namespace std;
6
7 int main()
8 {
9 float const commission percent = .02;
10
11 float shares bought = 750,
12 share price = 35.00,
13 total paid = shares bought * share price;
14
15 float total commision = total paid * commission percent,
16 amount paid = total commission + total paid;
17
18
19 cout << "Total amount paid without commission: $";
20 float amount paid = total commission + total paid;
21 cout << amount paid;
22
23 cout << "Total amount of commission: $";
24 cout << total commission;
25
26 cout << "Total amount paid including commission: $";
27 cout << total amount_paid << endl;
28 cout << endl << endl;
29
30
31 }
You are leaving a space in some of your variables.

Example:
commission percent could/should commission_percent or similar. The main thing is no spaces in the variables.

Take a look at the other variables with that problem.

Variable names in C++ can range from 1 to 255 characters.

All variable names must begin with a letter of the alphabet or an underscore(_).

After the first initial letter, variable names can also contain letters and numbers.

Variable names are case sensitive.

No spaces or special characters are allowed.

You cannot use a C++ keyword (a reserved word) as a variable name.

Source: https://www.tutorialspoint.com/What-are-the-rules-to-declare-variables-in-Cplusplus
Last edited on
Topic archived. No new replies allowed.