473,378 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Explaining the output for this code

Kindle Life 123
#include<iostream.h>
#include<stdlib.h>
void main()
{
randomize();
char status[][10]={"OK","START","ACTION";}
int Turn=5;Trick;
for (int count =3; count>0; count--}
{
Trick =random(count);
cout<<Turn+Trick<<Status[Trick}<<'@';
}

Options:
1.5START@6START@7ACTION@
2.6START@6ACTION@6START
3.7OK@6START@5ACTION@
4.6START@5OK@5ACTION@
Jun 4 '18 #1
2 1169
dev7060
636 Expert 512MB
- random(value) generates a random number from 0 to 'value-1'.

Possible outcomes:

-When, count =3,
Trick can be 0, 1 or 2
Turn+Trick can be (i.e. 5+trick) 5, 6 or 7
Status[Trick] can be Status[0], Status[1] or Status[2] i.e. OK, START OR ACTION
Valid options: 1, 2, 3 and 4

-When count is 2
Trick can be 0 or 1
Turn+Trick can be 5 or 6
Status[Trick] can be OK or START
Valid options: 1, 3 and 4

-When count is 1
Trick will be 0
Turn+Trick will be 5
Status[Trick] can be OK only

Hmm.., but there seems no option matching with the predicted output. I believe there should be a OK either in the 3rd or 4th option (1st one has been eliminated because of having 7).
Jun 4 '18 #2
Rabbit
12,516 Expert Mod 8TB
Also, that code looks like it has syntax errors so it's not going to run in the first place. Therefore, it won't produce any output
Jun 4 '18 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Ina Schmitz | last post by:
Hello all, I don't succeed in displaying the explain plan. I use IBM DB2 Universal Database 8.2. I tried to do the example given in the online help for "Visual Explain". The tables...
5
by: Jim Holder | last post by:
I tried building libpcap and tcpdump from my Red Hat 7 RPMs. The tcpdump make couldn't find ioccom.h and sockio.h. When a header file is missing, how do you find it? Thanks.
54
by: bnp | last post by:
Hi, I took a test on C. there was an objective question for program output type. following is the program: main() { char ch; int i =2;
22
by: Jaspreet | last post by:
I was recently asked this question in an interview. Unfortunately I was not able to answer it and the interviewer made a decision on my C strengths (or weekness) based on this single question and...
4
by: Bob Bedford | last post by:
Hello, I've a file wich must answer a request. For this my file must generate an XML output. That's work fine but sometimes I get a wrong mysql query. In this case, I've to manage the output...
3
by: rrs.matrix | last post by:
hi is there any system call in unix that will search for a file in the filesystem. someting like the find utility. if not then how should i search for a file in the file system. heard of...
2
NewYorker
by: NewYorker | last post by:
Hello comrades, I am a Dev-C++ beginner and need your help please. I've downloaded Dev-C++ in my computer but it seems to be one problem. After I type in my program,correctly, in the EDITOR and...
6
by: =?Utf-8?B?UGhpbA==?= | last post by:
I have seen the samples for Find that explain how to use the predicate, but they are always searching for a pre-defined value. What I don't understand is how to search for a random value stored in...
0
by: electrical | last post by:
/** Database implements a database of records */ public class Database { private Record base; // the collection of records private int NOT_FOUND = -1; // int used to denote when a...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.