Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why the answer is not 53.but output 56 25+28=53

+1 vote
asked Nov 18 by Chang Wei Kit (250 points)
// Example program
#include <iostream>
using namespace std;

int main()
{
    

    
    char gender,length,style,answer;
    int Price,Counter=0;
    
do{
    cout<<"Enter Your Gender(F/M):";
    cin>>gender ;
    
    cout<<"Enter Your Hair Length(S/M/L):" ;
    cin>>length ;
    
    cout<<"Enter Your Style(R/S):" ;
    cin>>style ;
    
    
switch (gender){
    
    
    case 'F':
      if (((length=='S')&&(style=='R')))
      {
      Price=25;
      }
      else if (((length=='S')&&(style=='S')))
      {
      Price=35;
      }
      else if (((length=='M')&&(style=='R')))
      {
      Price=30;
      }
      else if (((length=='M')&&(style=='S')))
      {
      Price=40;
      }
      else if (((length=='L')&&(style=='R')))
      {
      Price=35;
      }
      else
      {
      Price=45;
      }
      cout<<"Price:RM"<<Price<<endl;
      break;
      
    case 'M':
      
     if (((length=='S')&&(style=='R')))
      {
      Price=28;
      }
      else if (((length=='S')&&(style=='S')))
      {
      Price=33;
      }
      else if (((length=='M')&&(style=='R')))
      {
      Price=31;
      }
      else if (((length=='M')&&(style=='S')))
      {
      Price=36;
      }
      else if (((length=='L')&&(style=='R')))
      {
      Price=35;
      }
      else
      {
      Price=40;
      }
      cout<<"Price:RM"<<Price<<endl;
      break;
      default:
      cout<<"Not valid"<<endl;;
      
}

    cout<<"Add another customer?(Y/N):" ;
    cin>>answer ;
    Counter++ ;
    }while(answer =='Y') ;
   
    
    if(Counter==1)
    goto result1;
    
    else
     Price+=Price;
     goto result2;
    
    
    result1:
    cout<<"Total:RM"<<Price<<endl;
    return 0;
    
    result2:
    cout<<"Total:RM"<<Price<<endl;
    return 0;    
}

1 Answer

0 votes
answered Nov 18 by Peter Minarik (40,320 points)

The actual output depends on the input you provided to the program. So it's hard to tell what happened without knowing what you exactly did.

Also, using the goto command is not recommended as it makes the code hard to read and follow.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...