Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Program set

Program set

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
3 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    debby forbes
    wrote on last edited by
    #1

    Hello everyone. Currently, working on a program however i tried my first two programs using a driver but i still have an error. I'm not sure what the issue is. I'm new to c++ any assistance would be appreciated, Attached is the driver and 1 and 2 program. Thanks. Driver:

    #include
    using std::cout;
    using std::cin;
    using std::endl;

    #include
    //#include "Miscellaneous.h"

    void showMenu();
    int getResponse();

    int main()
    {

    int response;
    
    
    //NOTE: each time you finish writing a function and want to test it,
    //uncomment the case within the switch that calls that function.
    while ( ( response = getResponse() ) != 5 )
    {
        switch( response )
        {
    
            //case 1: multiplication(); cout<<"\\n\\n"; break;
            //case 2: numberGuess(); cout<<"\\n\\n"; break;
            //case 3: printSquare(); cout<<"\\n\\n"; break;
            //case 4: calculatePayroll(); cout<<"\\n\\n"; break;
        }
        system("pause");
    }
    
    cout<<"\\n\\nThank you and have a nice day!\\n\\n";
    
    return 0;
    

    }

    void showMenu()
    {

    system("cls");
    cout<<"\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n";
    cout<<"\* Press 1 to do multiplication    \*\\n";
    cout<<"\* Press 2 to play number guessing \*\\n";
    cout<<"\* Press 3 to print a square       \*\\n";
    cout<<"\* Press 4 to calculate payroll    \*\\n";
    cout<<"\* Press 5 to Quit                 \*\\n";
    cout<<"\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n";
    cout<<"=====> ";
    

    }

    int getResponse()
    {
    int response;
    showMenu();
    cin>> response;

    while( response < 1 || response > 5)
    {
        showMenu();
        cin >> response;
    }
    return response;
    

    }
    1 CASE: MULTIPLICATION

    #include
    using std::cout;
    using std::endl;
    using std::cin;
    #include
    #include
    void correctMessage( void );
    void incorrectMessage( void );
    void multiplication( void );

    int main()

    {
    srand( time( 0 ) );

    multiplication();
    return 0;
    }

    void correctMessage( void )
    {
    switch ( rand() % 4 ) {
    case 0:
    cout << "Very good!";break;
    case 1:
    cout << "Very good!";break;
    case 2:
    cout << "Very good!";break;
    case 3:
    cout << "Very good!";break;
    }
    cout << "\n\n";
    }

    void incorrectMessage( void )
    {
    switch ( rand() % 4 ) {

    case 0:
    cout << "No. Please try again.";break;
    case 1:
    cout << "No. Please try again.";break;
    case 2:
    cout << "No. Please try again!";break;
    case 3:
    cout << "No. Please try again!";break;
    cou

    L CPalliniC 2 Replies Last reply
    0
    • D debby forbes

      Hello everyone. Currently, working on a program however i tried my first two programs using a driver but i still have an error. I'm not sure what the issue is. I'm new to c++ any assistance would be appreciated, Attached is the driver and 1 and 2 program. Thanks. Driver:

      #include
      using std::cout;
      using std::cin;
      using std::endl;

      #include
      //#include "Miscellaneous.h"

      void showMenu();
      int getResponse();

      int main()
      {

      int response;
      
      
      //NOTE: each time you finish writing a function and want to test it,
      //uncomment the case within the switch that calls that function.
      while ( ( response = getResponse() ) != 5 )
      {
          switch( response )
          {
      
              //case 1: multiplication(); cout<<"\\n\\n"; break;
              //case 2: numberGuess(); cout<<"\\n\\n"; break;
              //case 3: printSquare(); cout<<"\\n\\n"; break;
              //case 4: calculatePayroll(); cout<<"\\n\\n"; break;
          }
          system("pause");
      }
      
      cout<<"\\n\\nThank you and have a nice day!\\n\\n";
      
      return 0;
      

      }

      void showMenu()
      {

      system("cls");
      cout<<"\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n";
      cout<<"\* Press 1 to do multiplication    \*\\n";
      cout<<"\* Press 2 to play number guessing \*\\n";
      cout<<"\* Press 3 to print a square       \*\\n";
      cout<<"\* Press 4 to calculate payroll    \*\\n";
      cout<<"\* Press 5 to Quit                 \*\\n";
      cout<<"\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n";
      cout<<"=====> ";
      

      }

      int getResponse()
      {
      int response;
      showMenu();
      cin>> response;

      while( response < 1 || response > 5)
      {
          showMenu();
          cin >> response;
      }
      return response;
      

      }
      1 CASE: MULTIPLICATION

      #include
      using std::cout;
      using std::endl;
      using std::cin;
      #include
      #include
      void correctMessage( void );
      void incorrectMessage( void );
      void multiplication( void );

      int main()

      {
      srand( time( 0 ) );

      multiplication();
      return 0;
      }

      void correctMessage( void )
      {
      switch ( rand() % 4 ) {
      case 0:
      cout << "Very good!";break;
      case 1:
      cout << "Very good!";break;
      case 2:
      cout << "Very good!";break;
      case 3:
      cout << "Very good!";break;
      }
      cout << "\n\n";
      }

      void incorrectMessage( void )
      {
      switch ( rand() % 4 ) {

      case 0:
      cout << "No. Please try again.";break;
      case 1:
      cout << "No. Please try again.";break;
      case 2:
      cout << "No. Please try again!";break;
      case 3:
      cout << "No. Please try again!";break;
      cou

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      debby forbes wrote:

      i tried my first two programs using a driver but i still have an error.

      Maybe if you explained what the error is, and where it occurs, we could make some suggestions.

      1 Reply Last reply
      0
      • D debby forbes

        Hello everyone. Currently, working on a program however i tried my first two programs using a driver but i still have an error. I'm not sure what the issue is. I'm new to c++ any assistance would be appreciated, Attached is the driver and 1 and 2 program. Thanks. Driver:

        #include
        using std::cout;
        using std::cin;
        using std::endl;

        #include
        //#include "Miscellaneous.h"

        void showMenu();
        int getResponse();

        int main()
        {

        int response;
        
        
        //NOTE: each time you finish writing a function and want to test it,
        //uncomment the case within the switch that calls that function.
        while ( ( response = getResponse() ) != 5 )
        {
            switch( response )
            {
        
                //case 1: multiplication(); cout<<"\\n\\n"; break;
                //case 2: numberGuess(); cout<<"\\n\\n"; break;
                //case 3: printSquare(); cout<<"\\n\\n"; break;
                //case 4: calculatePayroll(); cout<<"\\n\\n"; break;
            }
            system("pause");
        }
        
        cout<<"\\n\\nThank you and have a nice day!\\n\\n";
        
        return 0;
        

        }

        void showMenu()
        {

        system("cls");
        cout<<"\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n";
        cout<<"\* Press 1 to do multiplication    \*\\n";
        cout<<"\* Press 2 to play number guessing \*\\n";
        cout<<"\* Press 3 to print a square       \*\\n";
        cout<<"\* Press 4 to calculate payroll    \*\\n";
        cout<<"\* Press 5 to Quit                 \*\\n";
        cout<<"\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n";
        cout<<"=====> ";
        

        }

        int getResponse()
        {
        int response;
        showMenu();
        cin>> response;

        while( response < 1 || response > 5)
        {
            showMenu();
            cin >> response;
        }
        return response;
        

        }
        1 CASE: MULTIPLICATION

        #include
        using std::cout;
        using std::endl;
        using std::cin;
        #include
        #include
        void correctMessage( void );
        void incorrectMessage( void );
        void multiplication( void );

        int main()

        {
        srand( time( 0 ) );

        multiplication();
        return 0;
        }

        void correctMessage( void )
        {
        switch ( rand() % 4 ) {
        case 0:
        cout << "Very good!";break;
        case 1:
        cout << "Very good!";break;
        case 2:
        cout << "Very good!";break;
        case 3:
        cout << "Very good!";break;
        }
        cout << "\n\n";
        }

        void incorrectMessage( void )
        {
        switch ( rand() % 4 ) {

        case 0:
        cout << "No. Please try again.";break;
        case 1:
        cout << "No. Please try again.";break;
        case 2:
        cout << "No. Please try again!";break;
        case 3:
        cout << "No. Please try again!";break;
        cou

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        I've fixed you program for you, in order to perform correctly the multiplication case. All the other ones are up to you.

        #include using std::cout;
        using std::cin;
        using std::endl;

        #include
        #include void showMenu();
        int getResponse();

        void correctMessage( );
        void incorrectMessage( );
        void multiplication( );

        int main()
        {
        int response;

        //NOTE: each time you finish writing a function and want to test it,
        //uncomment the case within the switch that calls that function.
        while ( ( response = getResponse() ) != 5 )
        {
        switch( response )
        {
        case 1:
        multiplication(); cout<<"\n\n";
        break;
        //case 2: numberGuess(); cout<<"\n\n"; break;
        //case 3: printSquare(); cout<<"\n\n"; break;
        //case 4: calculatePayroll(); cout<<"\n\n"; break;
        default:
        if ( response < 5)
        cout << "sorry, not yet implemented\n\n";
        break;
        }
        }
        cout<<"\n\nThank you and have a nice day!\n\n";
        return 0;
        }

        void showMenu()
        {
        system("cls");
        cout<<"***********************************\n";
        cout<<"* Press 1 to do multiplication *\n";
        cout<<"* Press 2 to play number guessing *\n";
        cout<<"* Press 3 to print a square *\n";
        cout<<"* Press 4 to calculate payroll *\n";
        cout<<"* Press 5 to Quit *\n";
        cout<<"***********************************\n";
        cout<<"=====> ";
        }

        int getResponse()
        {
        int response;
        showMenu();
        cin>> response;

        while( response < 1 || response > 5)
        {
        showMenu();
        cin >> response;
        }
        return response;
        }

        void correctMessage( void )
        {
        cout << "Very good!\n";
        }

        void incorrectMessage( void )
        {
        cout << "No. Please try again.\n";
        }

        void multiplication( void )
        {
        int x, y, response = 0;
        srand( time( 0 ) );

        while ( response != -1 )
        {
        x = rand() % 10;
        y = rand() % 10;
        cout << "How much is " << x << " times " << y<< " (-1 to End)? "; cin >> response;
        while ( response != -1 && response != x * y )
        {
        incorrectMessage();
        cin >> response;
        }
        if ( response != -1 )
        {
        correctMessage();
        }
        }
        }

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups