C :: Guess 4 Int Array With How Many Are In Right And Wrong Positions

Feb 11, 2013

For an assignment I have to create a random array of four integers, and then I have to allow someone to input up to ten guesses to guess the array in the correct order. I also need to be able to display whatever was generated by inputting -1. Finally, after every guess I have to tell the inputter how many of the guessed integers are correct and in the correct position, as well as how many integers are correct but not in the correct position.

So far I've been able to get the random array to generate properly, but inputting negative one has no effect, although if I input it four times in a row I get to my 'lose' condition. Also, it only seems to allow the user to input 4 guesses and not 10 before going straight to the 'lose' condition. I need to get these issues sorted out before I can move on to showing how many guesses are right etc....

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time (NULL));

[Code] ....

View 3 Replies


ADVERTISEMENT

C :: Possible To Switch Two Array Positions?

Feb 12, 2015

I have a fundamental question due to my lack of understanding how arrays work.Let say I have a character array (byte array).

1. do array elements have memory adresses? i guess not but ....
2. if yes is it possible to switch two array positions? For examle:

a[x] change with a[y] for x,y < |a|

as oppose to changing values assigned to individual array positions.

View 2 Replies View Related

C :: Sorting Array Of Integers Between Two Positions Of Array

Apr 18, 2013

I am trying to create a code to sort an array of integer, but only between two positions of the array, not the all array.

like this:

array: 1 2 5 4 7 2 9 8
index: 0 1 2 3 4 5 6 7

i want to sort the array per exemple between the the index 2 and 5.the result is... array: 1 2 2 4 5 7 9 8

View 2 Replies View Related

C :: How To Rearrange Structure Element On The Basis Of Positions Given In Other Array

Apr 8, 2013

I want to rearrange the positions of structure elements on the bases of perm_array.

Code:
typedef struct gg{
element d;
int group;
} gg;
gg col_data[16];

[Code] ....

How can i rearrange structure element like {ptr+2,ptr+3,ptr+1,ptr+0} ?

View 2 Replies View Related

C++ :: Loop Through Indexes In Guess Array And Assign M Randomly

Jan 19, 2013

Just run a loop through each of the indexes in the guessarray and assign 'M' to them randomly.

View 2 Replies View Related

C/C++ :: Array Switches Wrong Values

Jun 7, 2014

I have a game that requires the switching of tiles. When I try to switch the blank tile (_) with 5, the 5 switches with the 8 instead of the tile switching with the blank tile. The code behaves the same with top row. I have observed that this only happen in the row and column bound by [0][0]; For example the four top left tiles ([8, 7, 5, are 4]) are behave erratically.

Here is sample code!

//swap if columns are equal and blank is to bottom
else if ((blankCol==tileCol) && (blankRow-tileRow==1)) {
temp = board[blankRow][blankCol];
board[blankRow][blankCol] = board[tileRow][tileCol];
board[tileRow][tileCol] = temp;
return true;
}

I am thinking perhaps there may be a double switch but then again why does it for only the left column and top row.

Attached image(s)

View 2 Replies View Related

C++ :: Find Index Of String Array - Get Wrong Return Value?

Apr 17, 2014

Here is my code to find the index of a string array whose string is equal to the query string. I have checked the program can return the correct index, but the cout result is totally wrong.

#include <iostream>
#include <string>
using namespace std;

[Code].....

View 4 Replies View Related

C++ :: Wrong Return Type When Returning Char Array As Pointer

Apr 25, 2014

I am writing a class Player which has several char arrays as private fields. I am trying to write a method which returns an array as a pointer, but doesn't alter the array in any way, thus the const.

Here is a snippet:

Code: class Player
{
private:
char state[MAX_STATE_CHAR + ONE_VALUE];
int rating;
char last[MAX_NAME_CHAR + ONE_VALUE];
char first[MAX_NAME_CHAR + ONE_VALUE];
int groupNumber = NEG_ONE;
public:
char * GetFirst() const
{
return first;
}

Visual studio is saying that the return type doesn't match.

View 3 Replies View Related

C++ :: Smart Array Class - Constructor Throws Wrong Exception

Jan 24, 2014

Writing a smart array class for my C++ class. I'm running into a problem where the constructor apparently throws the wrong exception. Compiled on G++ with C++11 extensions enabled.

Code:
// headers
#include <iostream>
#include <utility>
#include <cctype>
// stuff we need from namespace std
using std::cout;
using std::cin;

[Code] .....

When I try to check the error-handling code, when I enter a size less then two, Array's ctor throws InvalidSize, and gets caught, all good. But when I enter a letter, the ctor also seems to throw InvalidSize!

View 14 Replies View Related

C++ :: While Loop Age Guess

Feb 20, 2013

Write a C++ program that uses a while loop to guess a persons age, ask the user if the want to try again if no end the loop. Of course if they guess it the loop also ends

View 3 Replies View Related

C :: Minimum And Maximum In All Positions

Jan 4, 2015

I wrote a program to find the minimum and the maximum values from a vector. It works fine. What I'm trying to do is show the positions of said values and it's not working quite right. When I insert 4 elements: 2 0 1 3 it says:

"The min and max are 0 and 3
The position of the min is: 01
The position of the max is: 03"

What am I doing wrong? Here is the code:

Code:

#include <stdio.h>
#include <conio.h>
int main() {
int A[10], i, j, n, min, max, C[10], k=0, D[10], l=0;
printf("Insert no. of elements in vector A

[code]....

View 6 Replies View Related

C++ :: Calculate Sum Of Numbers In Given Positions

Dec 16, 2013

Question: Write a program that calculates sum of the numbers in the given positions.

Input specification : There will be 4 lines of data. You will be first given the size of the positions array (n). Then, the following line will have n integers which is an ordered list in increasing order and 0 < n ≤ 3000. The third line will give the size of the number array (m) where 0 < m ≤ 5000 and The last line will have m integers between -30000 and 30000.
Note: The positions start from 1 and goes until m.

Output specification : Show one integer number. Sum of the Numbers in the given Positions.

Sample Input I
5
2 5 7 9 10
10
1 8 7 5 17 15 6 7 19 12

Sample Output I
62

View 1 Replies View Related

C :: Guess Random Number Game

Aug 9, 2013

I have an error on my Guess the random number game.When you got the right answer it shows the "You got the right answer" and shows the "What is the number?" Here is the code.

Code:

#include<stdio.h>
main()
{
srand(time(0));
int x=rand() % 101,guess=0,tries=3;
printf("The computer will generate a random number, try and guess the random number.
}

[code]....

View 3 Replies View Related

C++ :: Program To Swap Positions Of Digits Of User

Oct 11, 2014

I'm using code blocks ....

1.Write a program to swap positions of digits of a user entered three-digit integer N, where N is equal or between 101 and 999. (i.e. if user enters 389 your program should print 983. If user enters 300 program should print 003). Repeatedly ask user for correct N, if he/she enters an integer N which is not in the range.

2. Given that y= 4*( 1- 1/3 + 1/5- 1/7+ 1/9-...plus or minus 1/N) Write a program using a for-loop or a while-loop to compute and print the sum of first 50 terms of y.

3. a) Write a user-defined function funGx to compute G(x), where

5 if x<-10

x^2 +(5/x) if -10 <=x<-5

x^2 - (5/x-5) if -5<=x<5

x^2 -(5/x) if 5<=x<10

-5 if x>=10

b) Call the user-defined function funGx in main function to compute and print G(x)values for x= -15.5 , x=5, and x= 0.5 in an informative sentence.

View 3 Replies View Related

C/C++ :: Placing Numbers In Random Positions In Matrix?

Oct 30, 2014

i have a problem with a bit of code (part of an as-yet incomplete program that creates a sort of maze with 10 roadblocks, and then finds the shortest route to the exit.

I don't know what it means, to put tags around my code, but I shall try to point out the problem bit clearly. It is not a long segment. This part is all working fine and printing the messages the user needs to see initially:

#include <stdio.h>
#include <stdlib.h>
int main() {
printf("The number -1 shall represent the position of the robot in the matrix.
"
"The number 99 shall represent the position of the exit.
"
"The number 100 shall represent all blocks.
"
"All other numbers represent the number of moves required to reach the occupied space from the robot's position.
");

Below is where is goes bad, and I really am not sure why. The program says it has stopped responding and gets grayed out, and then I get the error message, "An access violation (Segmentation fault) raised in your program.

I have tried using the debugger, and it only tells me it found 0 errors and 0 warnings.

srand(time(NULL));
int initialmatrix [8] [8];
initialmatrix [0] [7] = 99;
int numberofblocks=0;
int randomrow;

[code]....

View 5 Replies View Related

C++ :: Guess Number Game - Choosing Integer At Random

Jun 11, 2013

Write a program that plays the game of guess the number.the program chooses the number to be guessed by choosing an integer at random in the range 1-1000. The program then types 'i have a number between 1 and 1000,can you guess number? Then the player then types the first guess, the program responds.

View 1 Replies View Related

C Sharp :: Storing Positions Of DrawRectangle Into A List - Only Stores Last X And Y?

Oct 12, 2012

I am trying to store values of X and Y into a list like this:

if (pictureBox1.Image != null) {
                    draw = true;
                    Graphics g = Graphics.FromImage(imageFile);
                    Pen pen1 = new Pen(color, 4);
                    g.DrawRectangle(pen1, e.X - 3, e.Y - 2, 5, 5);

[Code] ....

It stores all the nodes but it stores them as the same position, I am not sure how to make them act independently.

View 2 Replies View Related

C++ :: Math Tutor - Guess Correct Answer Of Random Numbers

Jul 11, 2014

Objective: Guess the correct answer of the random numbers

Problem: I guess the correct answer but the program keeps telling me that I'm INCORRECT.

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, const char * argv[]) {
const int MIN_VALUE = 1; // Constants
const int MAX_VALUE = 200;

[Code] ....

View 2 Replies View Related

C++ :: Guessing Game Program - Ask User To Guess Computer Generator Number

Feb 11, 2013

I'm currently creating a guessing game program where the user will be asked to guess the computer generated number. Once the program is finished, at the end the user will be asked if they want to play again. If the user types "Y or Y" the program will loop and when the user types "n or N" it will not loop. Check out my code below.

#include<iostream.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#define g gotoxy
void main(){
int a,l,b,guess,row,col,answer,num,clue=5;

[Code] ....

I can't loop this program.

View 3 Replies View Related

C/C++ :: Keeping List Of User Guesses And Output Message If Guess Is Duplicate

Apr 19, 2015

The label "You already picked that" doesn't always appear. Sometimes it does, but only if a duplicate has been entered at least 3 times. I haven't been able to correct this. I am new to programming and array-based lists.

//Objective: randomly generate an integer between 1 and 100, input user guess as to what number it is, and output "correct!" if user guess is the random number, or output "Too high" if the user guess is too high, or output "too low" if the user guess is too low, "you already entered __" if a duplicate is entered and allow the user to keep guessing until they guess the correct number

//libraries
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std;
struct Guess {

[Code] ....

View 9 Replies View Related

C++ :: Simulated Radio Station Holding A Contest - Guess Number / Sequential Search

Dec 14, 2014

I have an assignment to write the code for a simulated radio station holding a contest. The contest is for a "caller" (user input obviously) to guess a number from 1 to 500. The "randomly generated" numbers are already chosen and are being stored in a .txt file. The code is to search for number guessed by the caller and if they are wrong, next caller until a caller is correct. The end result is to display the winning number, the indexed location the number was found, and how many callers guessed. This is what I have...

Code:
#include<iostream>
#include<fstream>
using namespace std;
int sequenSrch(const int prizeArray[], int arrayLength, int searchedItem);
int guess();

[Code] ....

I'm not sure if I am even on the right track... when I pass something into the sequenSrh(); the code compiles, asks for the number to be guessed and ends.

View 2 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C++ :: Write A Loop Assigning Variable X To All Positions Of String Variable

Sep 8, 2013

I have to write a loop assigning a variable x to all positions of a string variable and I'm stuck. I don't have extensive experience with arrays and I'm also a bit confused about C-String. The problem is below.

"Given the following declaration and initialization of the string variable, write a loop to assign 'X' to all positions of this string variable, keeping the length the same.

char our_string[15] = "Hi there!";

(Please note this is a 'C-string', not C++ standard string.)"

View 5 Replies View Related

C++ :: Variable Assigned Wrong Value?

Nov 15, 2012

Consider the following:

Code:
float foo( float const *bar )
)
{
float temp;
temp = *bar;
...
}

Something I am noticing is that temp right after the assignment to *bar, is not the same value as *bar. This is for a project at work and the code runs on an embedded board with an ARM processor. I've copied the function into a standalone program for both Visual Studio and Code::Blocks and it works correctly there.

View 12 Replies View Related

C++ :: Fees Showing Up Wrong On Program

Feb 19, 2014

I'm writing a program that shows check fees for different amounts of checks. My other fees are showing up right but the .10 cents is not. It's showing up as .08 cents per check when I run the program.

Oh yeah the + 10 is for a $10 fee

Code:
else if (checks < 20 || checks >= 0) {
fee = .10 * checks + 10;
cout<< "Bank service charge for the month is $ " << setprecision(4) << endl;
}

View 3 Replies View Related

C# :: Des Encryption Produces Wrong Output

Feb 14, 2012

I have the following function:

Code:
public static void Des(byte[] key, byte[] inBuf, byte[] outBuf) {
if (key.Length != 8 || inBuf.Length != 8 || outBuf.Length != 8) {
throw new Exception("Des: Buffer or key length incorrect.");
}

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

[Code] ....

I do not get the expected output of

Code: { 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 }

instead I get

Code: { 0xC6, 0x61, 0x8D, 0x63, 0x0B, 0x39, 0x31, 0xB0 } am I doing something wrong?

I've even tried reversing the byte order of the test data, and I don't get the right result. I've tested the same data using C++ with CryptoPP on Linux, and I get the expected result, but I'm porting this code to run on .Net, and this is my main stoppage in the process at the moment.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved