C++ Programming Homework

Hello. I am trying to figure out what is wrong with my program. Currently it is telling me that "C2228: left of '.cin' must have class/struct/union" and "C2181: illegal else without matching if". I've been trying to figure out what I did wrong but everything I do does not work. The program is supposed to accept either "S" or "J" and show the certain amount of money that letter makes.

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
#include <iostream>
using namespace std;
int main()
{

int S;
int J;



cout << "Please Enter S for Senior Engineer and J for Junior Engineer" << endl.

cin >> S >> J;

if ( S == 'S') {
	cout << "The Senior Engineer makes $1700 per week.\n";
else cout << "Error.\n";

}

if ( J == 'J') {
	cout << "The Junior Engineer makees $900 per week.\n";
else cout << "Error.\n";
}

cout << "Thank you";


return 0;
}
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
#include <iostream>

int main()
{
	std::cout << "Please Enter 'S' for Senior Engineer and 'J' for Junior Engineer:" << std::endl;

	char c;
	std::cin >> c;

	switch (toupper(c))
	{
	case 'S':
		std::cout << "The Senior Engineer makes $1700 per week.\n";
		break;
	case 'J':
		std::cout << "The Junior Engineer makees $900 per week.\n";
		break;
	default:
		std::cout << "Error.\n";
		break;
	}

	std::cout << "Thank you" << std::endl;

	system("PAUSE");
	return 0;
}
Last edited on
closed account (48T7M4Gy)
line 11 ; not .
line 15 and 19 bracketing is incorrect

Get those fixed and re-run
closed account (48T7M4Gy)
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
#include <iostream>

using namespace std;

int main()
{
    
    char S = ' '; // <--
    char J = ' '; // <--
    
    cout << "Please Enter S for Senior Engineer and J for Junior Engineer" << endl; // <--
    
    cin >> S >> J;
    
    if ( S == 'S')
        cout << "The Senior Engineer makes $1700 per week.\n";
    else
        cout << "Error.\n";
    
    if ( J == 'J')
        cout << "The Junior Engineer makees $900 per week.\n";
    else
        cout << "Error.\n";
    
    cout << "Thank you";
    
    return 0;
}
Thank you very much!
Topic archived. No new replies allowed.