Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Currently discussion classes in c++ with no fancy libraries except iostream, nam

ID: 3671330 • Letter: C

Question

Currently discussion classes in c++ with no fancy libraries except iostream, namespace std and string. (begginers)

the program has the following choices: +, -, R for reset, and X for exit.

when you press + the program will increment or when you press - will decrement the count.

If the object returns and error, do not show the count. Inform the user that an error has occurred. No keys will produce a valid output until the user resets the counter by pressing R. When R is pressed, the count goes back to zero (this is done by the object) and error is reset to zero.

X will exit the program.

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

int main()
{
char ch;
int count = 0;
int error = 0;
while(true)
{
    cout<<" Program has the following choices: +, -, R for reset, and X for exit.";
    cin>>ch;

    if(ch=='+'||ch=='-'||ch=='R'||ch=='X')
    {
      if(ch=='+')
        count++;
      else if(ch == '-')
        count--;
      else if(ch == 'R')
        count = 0;
      else if(ch == 'X')
        break;

      cout<<"Count = "<<count<<endl;
    }else
    {
      error = 1;
      while(ch!='R')
      {
        cout<<"Error has occured!!! Press R for reset ";
        cin>>ch;
      }
        cout<<"Counter resetted ";
        count = 0;
        error = 0;
    }
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote