?
Solved

basic C++ question

Posted on 2000-04-04
1
Medium Priority
?
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
mnewton022700 earned 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

762 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