Click here to Skip to main content
11,500,844 members (79,709 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Homework
 
#include <iostream>using namespace std;

int main()
{
    cout <<"S = Sales"<< endl;
    cout <<"A = Accounting"<< endl;
    cout <<"E = Engineering!"<< endl;
    cout <<"H = Human Resouces"<< endl;
    cout <<"F = Finance!"<< endl;
    
    char dept;
    cout << "Enter your selection: ";
    cin >> dept;
switch (dept)
    {
        cout<<dept;
       case S:  cout << "Sales\n";  // fall through
       case A:  cout << "Accounting\n"; // fall through
       case E:  cout << "Engineering!\n"; // fall through
       case H:  cout << "Human Resouces\n"; // fall through
       case F:  cout << "Finance!\n";
              break;
     }
   cout << "\n\n";
    return 0;
}

please can someone help me out with this

Write a C++ program that receives input for 5 children and prints the names of their teacher inside a loop. (Teachers names are fictitious. So give your own name).

10. Write a program to display the following menu:

• S – Sales
• A – Accounting
• E – Engineering
• H – Human Resource
• F – Finance
1. Based on the user’s selection, display the department name.
• Hint : use Switch…case.

[edit]unnecesary code block removed[/edit]
Posted 25-Nov-12 0:18am
Edited 26-Nov-12 22:39pm
nv331.7K
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Review your switch statement[^].

For one each case should have it own break; and also consider adding a default: case for when incorrect input is supplied.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

please i have tried and tried Permalink can you help me out ,how do i figure it out
  Permalink  
Comments
Nelek at 25-Nov-12 7:15am
   
Please don't post solutions to add information, to ask something or to comment another user.
- To add information to your message, you can use the widget "Improve question" / "Improve solution" at the bottom of your text.
- To ask/answer a user, you can use the widget "Have a question or comment?" (as I am doing right now with you) or the widget "reply" in another comment.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

#include <iostream>

using namespace std;
 
void Sales()
{
    cout << "Sales";
}
void Accounting()
{
    cout << "Accounting";
}
void Engineering()
{
    cout << "Engineering";
}
void HumanResouces()
{
    cout << "Human Resouces";
}
void Finance()
{
    cout << "Finance";
}
int main()
{
  int dept;
 
  cout<<"1. Sales\n";
  cout<<"2. Accounting\n";
  cout<<"3. Engineering\n";
  cout<<"4. Human Resouces\n";
  cout<<"5. Finance\n";
  cout<<"6. Exit\n";
  cout<<"Selection: ";
  cin>> dept;
  switch ( dept ) {
  case 1:            // Note the colon, not a semicolon
    Sales();
    break;
  case 2:            // Note the colon, not a semicolon
    Accounting();
    break;
  case 3:            // Note the colon, not a semicolon
    Engineering();
    break;
  case 4:            // Note the colon, not a semicolon
    HumanResouces();
    break;
  case 5:            // Note the colon, not a semicolon
    Finance();
    break;
  case 6:            // Note the colon, not a semicolon
    cout<<"Thank you for your Selecting!\n";
    break;
  default:            // Note the colon, not a semicolon
    cout<<"Error or  bad input, quitting\n";
    break;
  }
  cin.get();
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

You should do it like this:
#include <iostream>
using namespace std;
 
int main()
{
    cout <<"S = Sales"<< endl;
    cout <<"A = Accounting"<< endl;
    cout <<"E = Engineering!"<< endl;
    cout <<"H = Human Resouces"<< endl;
    cout <<"F = Finance!"<< endl;
    
    char dept;
    cout << "Enter your selection: ";
    cin >> dept;
	switch (dept)
    {
        cout<<dept;
	case 'S':  cout << "Sales\n"; break; // fall through
	case 'A':  cout << "Accounting\n";break; // fall through
	case 'E':  cout << "Engineering!\n";break; // fall through
	case 'H':  cout << "Human Resouces\n"; break;// fall through
	case 'F':  cout << "Finance!\n";break;
	default:cout<<"input error!!!"<<endl;
		break;
	}
	cout << "\n\n";
    return 0;
}
Because the dept is a char type, so the behind the case should add ' '.
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

should use break for each case statement.
consider the switch statement format.
switch (expression)
{
case valueOne: statement;
                   break;
case valueTwo: statement;
                   break;
....
case valueN:   statement;
                   break;
default:       statement;
}

NOTE: It is almost always a good idea to have a default case in switch statements. If you have no other need for the default, use it to test for the supposedly impossible case, and print out an error message; this can be a tremendous aid in debugging.


so modify your switch statement like this
    switch (dept)
    {
        cout<<dept;
       case S:  cout<< "Sales\n";  // fall through
                break;
       case A:  cout<< "Accounting\n"; // fall through
                break;
       case E:  cout<< "Engineering\n"; // fall through
                break;
       case H:  cout<< "Human Resouces\n"; // fall through
                break;
       case F:  cout<< "Finance!\n";
                break;
       default: cout<<"Enter a valied character"<<endl;
     }
  Permalink  
Comments
Shyne.my at 25-Nov-12 7:43am
   
Please i have done it like this but Please can you help me if i want to use Char for the variables instead of int data type,i tried using it but not work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 395
1 Maciej Los 215
2 Peter Leow 215
3 DamithSL 165
4 Ralf Meier 134
0 Sergey Alexandrovich Kryukov 435
1 Maciej Los 345
2 DamithSL 285
3 Peter Leow 260
4 OriginalGriff 177


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100