Click here to Skip to main content
15,918,889 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
FlavourArrayInt[10] = array[] 
SauceArrayBool[] 
NutsArrayBool []  
SprinklesArrayBool[] 
 
Print "How many Customers would you like to cater for at once:" 
Set input as Count_Value {Default assumption is 10, as per question} 
 
While( index <= Count_value ) Do {assume first value is 1} 
 
display "Customer" + count_value 
count_value = count_value + 1 
print "What is your flavour of ice-cream (f1, f2, f3)" 
	get input 
  set FlavourArrayStr[count_Value] to input 
display "1. Vanilla 2. Chocolate 3. Strawberry  Which one you prefer (1, 2, 3) : "  
                    read input

print  "Would you like sauce" 
	get input 
if input equals "Y" 
then set SauceArrayBool[count_value] =	"Y" 
else set SauceArrayBool[count_value] ="N" 
set SauceArrayInt[count_value] 
 
print  "Would you like nuts?" 
	get input 
if input equals "Y" 
then set NutsArrayBool [count_value] =	"Y" 
else set NutsArrayBool[count_value] ="N" 
 

print  "Would you like sprinkles" 
	get input 
if input equals "Y" 
then set SprinklesArrayBool [count_value] = "Y" 
else set SprinklesArrayBool [count_value] ="N" 
set SprinklesArrayBool [count_value] 
 
Print "For Customer : " + index 
Print "Your Flavour was" + FlavourArrayInt[index] 
Print "Your sauce was" + SauceArrayInt [index] 
Print "Your Nuts Option was" + NutsArrayBool[index] 
Print "Your Sprinkles Option was" + SprinklesArrayBool[index] 
 
end while loop


This is the task:
Consensus algorithm”: A group of ten people need to decide which one flavor of ice cream they will all order, out of three options. The algorithm can question and re-question the participants, and present the answers to the participants, until a consensus is reached. This exercise is somewhat more open-ended. Add your assumptions if necessary. Obviously, this algorithm might never result in an answer. Deal with that too.
Posted
Updated 18-Oct-12 23:37pm
v3
Comments
OriginalGriff 18-Oct-12 3:06am    
We can't answer that.
1) That isn't code - it's psuedo code rather than compilable c++ as you have tagged your question.
2) We don't know what it is supposed to do - so we can't even begin to evaluate if it is correct. If this is intended to run an MRI scanner, then it is clearly wrong. Other than that, we can't tell.
Have you tried implementing it and seeing what it does?
Member 9523460 18-Oct-12 3:16am    
hi Griff
you are correct, there is however no option for pseudo code.

The code is 100% correct. The only thing is that there does not exist a version of C++ compiler which can compile this particular piece of code. You need to write your own C++ compiler to execute it and check the output.

Check the rules for posting the questions on CP here[^]
 
Share this answer
 
Comments
Member 9523460 18-Oct-12 6:40am    
thank you
No, it is not. (As you didn't tell us, what the code is supposed to do, this answer is as good as any other :-)

As "the Griff" already told you, this looks like some pseudo code, which cannot be compiled nor tested.

From looking at your pseudo code, I would say that the use of your count_value variable in the loop is incorrect. I assume you meant to use "index" instead, because it designates your current customer. (You spelled the count_value variable differently in some places, like Count_Value and Count_value; was that intentional?)

Some of the lines of your pseudo code are unclear, like:
set SauceArrayInt[count_value] 


The principal logic of your code is mostly trivial. What would you like us to check on a simple prompt and output loop?
 
Share this answer
 
Comments
Member 9523460 18-Oct-12 5:34am    
Yes the logic, this the question, do ecuse as I'm new...

Consensus algorithm”: A group of ten people need to decide which one flavor of ice cream they will all order, out of three options. The algorithm can question and re-question the participants, and present the answers to the participants, until a consensus is reached. This exercise is somewhat more open-ended. Add your assumptions if necessary. Obviously, this algorithm might never result in an answer. Deal with that too.
Stefan_Lang 19-Oct-12 5:37am    
I added that information to your question.
Some problems:

0. The comments in your code indicate there is more information about your task that you haven't shared yet.

1. The tag on your question says C++, but the code looks like BASIC. While it is obviously only pseudo-code, the entire structure of the code isn't even remotely C-style. For one you should at the very least define the type of variables that you are using, and should use proper syntax for blocks ('{' and '}') and comments ('/*' and '*/'). The less your psuedo code looks like actual C code, the more likely you'll introduce mistakes when implementing it. (and the harder it is for others - like us - to understand it)

2. I see 'count_value', 'Count_value', 'count_Value' and 'Count_Value'. While unproblematic in pseudo code, you should really take care of your spelling when implementing this, as the compiler is case-sensitive.

3. Half of your code (nuts, sprinkles sauce) isn't related to your actual task. However, most of the actual task (finding a consensus) isn't done yet. Why don't you just focus on what you need and get it solved before needlessly complicating it?

4. Some algorithmic problems:
- you defined an array of size 10, and afterwards asked for the required size? Since the task told you to assume 10, don't bother asking. Or if you ask, define the array afterwards.
- you increment your index (or count_value that you erroneously used instead) rather early in the loop, but still reference it later. That way you're accessing one array element in the first part of the loop and another later. Don't do that! Always increment either at the end of the loop, or at the start. C/C++ style for loops make it really easy to do this, so use those for pseudo code too!
- a word of warning about comparing, and specifically user input: don't ever expect the user will enter a valid option, or respect case-sensitivity. Also, the comparison operator in C/C++ is '=='. The operator '=' means assgnment of a value, and even if this is pseudo code, you should distinguish the two!
 
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