Solved

basic C++ question

Posted on 2000-04-04
1
217 Views
Last Modified: 2010-04-02
Hi!
I'm starting to learn C++
I'm trying to do the following:

void evaluateCommand(Coins & piggyBank, char choice)
{
      int quarters, dimes, nickels, cents;
      switch(choice)
      {
      case 'B':case 'b':
            cout <<"Total amount is $" << piggyBank.total();
            break;
      case 'C':case 'c':
            cout <<"C was chosen";
            break;
      case 'D':case 'd':
            cout <<"How many quarters? ";
            cin >>quarters;
            cout <<"How many dimes? ";
            cin >>dimes;
            cout <<"How many nickels? ";
            cin >>nickels;
            cout <<"How many cents? ";
            cin >>cents;
            //piggyBank.depositChange(makeDepositObject(quarters, dimes, nickels, cents));
            Coins deposit(quarters,dimes,nickels,cents);
            piggyBank.depositChange(deposit);
            break;
      case 'P':case 'p':
            cout <<"P was chosen";
            break;
      case 'Q':case 'q':
            cout <<"Good bye!";
            exit(0);
      default:
            cout <<choice<<" is a invalid command";
            break;
      }


It works fine if I make a function to initialize the object(commented out section), but it throws an 5 error messages "initialization of 'deposit' is skipped by 'case label." when I try to directly initialize the object with in a case statement.  Is it suppose to do that or am I doing something wrong?

Thanks

0
Comment
Question by:chulsoft
1 Comment
 
LVL 3

Accepted Solution

by:
mnewton022700 earned 50 total points
ID: 2685523
You need to put brackets around the stuff in the "case 'D'" section

case 'D':case 'd':
{
cout <<"How many quarters? ";
cin >>quarters;
cout <<"How many dimes? ";
cin >>dimes;
cout <<"How many nickels? ";
cin >>nickels;
cout <<"How many cents? ";
cin >>cents;
//piggyBank.depositChange(makeDepositObject(quarters, dimes, nickels, cents));
Coins deposit(quarters,dimes,nickels,cents);
piggyBank.depositChange(deposit);
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now