





Please login

Prepinsta Prime
Video courses for company/skill based Preparation

Prepinsta Prime
Purchase mock tests for company/skill building
Fully Automatic Vending machine

TCS Coding Question Day 3 Slot 1 – Question 1
This is one of the previous year coding question of TCS NQT, which was held in October. The difficulty level of this question ranges from medium to high, so we would suggest that you should go through this question thoroughly
FULLY AUTOMATIC VENDING MACHINE
Problem Statement
FULLY AUTOMATIC VENDING MACHINE – dispenses your cuppa on just press of button. A vending machine can serve range of products as follows:
Coffee
- Espresso Coffee
- Cappuccino Coffee
- Latte Coffee
Tea
- Plain Tea
- Assam Tea
- Ginger Tea
- Cardamom Tea
- Masala Tea
- Lemon Tea
- Green Tea
- Organic Darjeeling Tea
Soups
- Hot and Sour Soup
- Veg Corn Soup
- Tomato Soup
- Spicy Tomato Soup
Beverages
- Hot Chocolate Drink
- Badam Drink
- Badam-Pista Drink
Write a program to take input for main menu & sub menu and display the name of sub menu selected in the following format (enter the first letter to select main menu):
Welcome to CCD
Enjoy your
Example 1:
- Input:
- c
- 1
- Output
- Welcome to CCD!
- Enjoy your Espresso Coffee!
Example 2:
- Input
- t
- 9
- Output
- INVALID OUTPUT!
#include <stdio.h>
int main()
{
char c[3][20]={"Espresso Coffee","Cappuccino Coffee","Latte Coffee"};
char t[8][30]={"Plain Tea","Assam Tea","Ginger Tea","Cardamom Tea","Masala Tea","Lemon Tea","Green Tea","Organic Darjeeling Tea"};
char s[4][20]={"Hot and Sour Soup","Veg Corn Soup","Tomato Soup","Spicy Tomato Soup"};
char b[3][20]={"Hot Chocolate Drink","Badam Drink","Badam-Pista Drink"};
char str[]="Welcome to CCD!\nEnjoy your ";
char ch;
int item, i;
scanf("%c",&ch);
scanf("%d",&item);
if(ch=='c')
{
for(i=0; i<3; i++)
{
if(item==i+1)
{
printf("Welcome to CCD!\nEnjoy your %s!",c[i]);
break;
}
}
if(i==3)
{
printf("INVALID OPTION!");
}
}
else if(ch=='t')
{
for(i=0; i<8; i++)
{
if(item==i+1)
{
printf("Welcome to CCD!\nEnjoy your %s!",t[i]);
break;
}
}
if(i==8)
{
printf("INVALID OPTION!");
}
}
else if(ch=='s')
{
for(i=0; i<4; i++)
{
if(item==i+1)
{
printf("Welcome to CCD!\nEnjoy your %s!",s[i]);
break;
}
}
if(i==4)
{
printf("INVALID OPTION!");
}
}
else if(ch=='b')
{
for(i=0; i<3; i++)
{
if(item==i+1)
{
printf("Welcome to CCD!\nEnjoy your %s!",b[i]);
break;
}
}
if(i==3)
{
printf("INVALID OPTION!");
}
}
else
{
printf("INVALID INPUT!");
}
return 0;
}
menu = [['Espresso Coffee','Cappuucino Coffee','Latte Coffee'], ['Plain Tea',
'Assam Tea','Ginger Tea','Cardamom Tea','Masala Tea','Lemon Tea','Green Tea',
'Organic Darjeeling Tea'], ['Hot and Sour Soup','Veg Corn Soup','Tomato Soup',
'Spicy Tomato Soup'], ['Hot Chocolate Drink', 'Badam Drink',
'Badam-Pista Drink']]
m = input()
if m=='c' or m=='t' or m=='s' or m=='b':
if m=='c':
submenu = int(input())
if submenu in range(3):
print('Welcome to CCD!\nEnjoy your {}!'.format(menu[0][submenu-1]))
else:
print("INVALID INPUT")
if m=='t':
submenu = int(input())
if submenu in range(8):
print('Welcome to CCD!\nEnjoy your {}!'.format(menu[1][submenu-1]))
else:
print("INVALID INPUT")
if m=='s':
submenu = int(input())
if submenu in range(4):
print('Welcome to CCD!\nEnjoy your {}!'.format(menu[2][submenu-1]))
else:
print("INVALID INPUT")
if m=='b':
submenu = int(input())
if submenu in range(3):
print('Welcome to CCD!\nEnjoy your {}!'.format(menu[3][submenu-1]))
else:
print("INVALID INPUT")
else:
print("INVALID INPUT!")
Day 2 Slot 2 Question 1
Click on the below button to study Day 2 Slot 2 Question 1 of TCS NQT Coding 2020 exam
TCS Coding Questions
Click on the below button to study more TCS Coding Question
Login/Signup to comment