Click here to Skip to main content
15,889,853 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, can anyone help me write this program? Write a program that asks the user to enter a letter between the letters a, b and q. If the user enters otherwise, warn and ask the user to enter one of these three letters again. The following operation must be performed for each letter entered by the user.
Input a: Receives a number from the user as the side of a square and then prints the perimeter of the square. And again ask the user to enter a letter between a, b and q. Input b: Receive a number from the user as the side of a square and then print the area of ​​the square. And again ask the user to enter a letter between a, b and q.
Input q: Completely exit the program.

What I have tried:

I can not write this program with c ++ and I get errors every time
Posted
Updated 13-Dec-21 20:25pm
Comments
Patrice T 14-Dec-21 0:56am    
You have a secret error in your secret code.
CPallini 14-Dec-21 2:05am    
Then show us your code and we will help you to fix the errors.

Nobody is going to write your code for you. That's not helping you at all.

If you show the code you have and list the errors you're getting, we can help you fix those.
 
Share this answer
 
This could be done with a do while loop and a switch statement, something like:

C++
int main()
{
  char c;
  do
  {
    // ask the use to insert a character, assing it to 'c'
    switch(c)
    {
    case 'a':
      // ask the user to input the side of the square, compute the perimeter and output it
      break;
    case 'b':
      // ask the user to input the side of the square, compute the area and output it
      break;
    default:
     // if (c != 'q') warn the user about incorrect input
      break;
    }
  } while ( c != 'q');
 
}
 
Share this answer
 
What about visiting some Learn C++ tutorial and start coding.

It is a homework which is solvable when you acquired the basic skills in coding.

Tip: install some IDE like Microsoft Visual Studio.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900