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....
I am trying to make a program which manages the data of 5 different patients (its an uni assignment), and i want to use a switch case as a menu to switch between the patients. All other functions (as for example putting the infromation on a file) work, but i cant figure out to bring the switch to work. First it asks for the number of the patient which should be worked with, this works perfectly, but afterwards changiung between the persons doesnt work as thought. It should ask everytime after it switches to one patient (i removed some functions to make it easier to read) and then asks to which it should jump next. If i put the number of one case (lets say 3) it just stops the program.
********Example: user@pc ~/wherever $ ./program current variables: jo = 2 a = 0 1 //the entered number The variable a = 1 patient 1 Enter the number of the next patient2 // and then it closes **************
The same thing happens if i compile an example code from a book, it writes the first case and then stops.
I looked already through the forum but didnt find a person with a similar problem, maybe i didnt dig deep enough.
I am running Linux Mint 17 and use gcc as compiler.
Code:
include <stdio.h> #include <stdlib.h> int a=0; int jo=2; int main(void){ printf("current variables: jo = %d a = %d
so I am trying to have an switch statement array. but every time i complete a case statement the whole process is returned. the thing is i want the menu to stay up even if i complete the case.
I have tried to search all about strings,I have the occurrences and have worked out what letter corresponds with which. I have searched that much i can remove the vowels and reverse my string but I dont know how to swap them. This is what i have this far. When it compiles it just prints the decipher is:
If i even find out am i on the right track ive used caps when swapping to try and stop the doubles over writing,...
#include<stdio.h> #include<string.h> int main(void){ int i,count=0; char secretText[] = "lopsy, hssepokd wl okrhsowk:
How do I convert dna from an array to complementary dna.
void print_reverse_complement(const char dna[]) {
the above function will convert DNA to Complementary DNA.. i.e A=T, C =G, G=C and T=A.
The prompt should look like: (asks user for dna sequence and stores into array) (prints back entered sequence)DNA sequence: ATCGGCATA DNA complement: TAGCCGTAT DNA reverse complement: TATGCCGAT
Then how would I do the same thing, but this time the reverse complement?
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
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.
I have a seat allocation algorithm for an airplane 30 x 6 seats. The plane is 'split' front (1 - 15) and back (16 -30), right (A,B,C) and left (D,E,F). I am placing passengers in window seats front right centre (15A) first then back left centre (16F) followed by (15F) followed by (16A). This will continue for single passengers middle seats then aisle.
Another part of the algorithm is to ensure parties >2 or <=6 to sit together in an empty row, if not possible the party will be split as to not have a person in the party sitting alone firstly. i.e. 6 is 3 + 3 or 2 + 2 + 2 or 4 + 2 or 3 + 2 + 1 or 4 + 1 + 1 or 3 + 1 + 1 + 1 and so.
I have got it working for one person but seating two people is a bit more difficult. I am trying to get 15A,15B then 16E,16F then 16A,16B then 15E,15F then 16C 16D and 15C 15D.
This code only allocates passengers 15 A 15B then 15C 15D then 15E 15F
//seat allocation for two people public bool[,] seatTwoPerson(bool[,] seatArray, int startCol, int endCol, int directionX, int startRow, int endRow, int directionY) { //loop through seatArray section determined by parameters //for (int col = startCol; directionX < 0 ? col >= endCol : col < endCol; col += directionX)
Just making typical console game where hero moves with w a s d.
However, in my code, while a and w work (minusing), s and d dont work (adding). I have used a switch statement to change the char position of the hero based on kbhit.When you hit s or d, the buttons that add 1 to the 2nd dimension of the array, the screen goes crazy!
#include <iostream> #include <string> #include <conio.h> #include <ctime> #include <cstdlib> using namespace std; const char PLAYER = 'H';
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.
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;
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.)"
I want to make something like some users using the same machine so they need to be registered to the system and the their id something like this (H510698541) and their information should appear on the screen.
okay so like case 2 and 3 is not working, also the program is still not finish but why isn't case 2 and 3 not functioning well on the switch part? case 1 works just fine
Code: #include<stdio.h> main () { //passcode part (passcode is 1234)
I'm currently doing a project which will trigger an alarm and light up an LED when a character 'E' is detected from a bluetooth input. I'm supposed to program a pic18f4525 board.
I'm having troubles with where to start on the codes to enable the LED to light up upon detection of character 'E'. I'm using ports RD0-RD3. This is how I initialised them in the main loop.
Code: TRISD = 0b11000000; PORTD = 0xC0;
Am I doing the initialising right? Also, how to program it to light up when the character's detected?
Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char).
So does that mean switch statements can only test if variable == value and nothing more, like > < >= <= != etc... ? I tried to make a program to test this and it seems like switch statements are limited to == but I'm not sure, maybe I'm doing something wrong.
This is the program I tried to make to test this:
Code: #include <stdio.h> int main () { int n;
[Code]....
So is it true that switch statements only work with the built in == operator? if that was the case then I would feel rather meh about switch statements.
I'm making a game in OpenGL GLUT. A ball is going to move forwards along the Z axis and hit a wall. I want to be able to move the ball left and right, up and down before firing it off on the Z axis. I'm using glutSpecialKeys for this, and I've got everything set up, but I'm not sure how I use it with a switch statement? Here is a snippet of code:
void Special_Keys (int key, int x, int y){ switch(key){ case GLUT_KEY_UP: //do something break; case GLUT_KEY_DOWN: //do something
[Code] .....
Where the comment is saying "do something", I'm not sure what I actually need to do? Is it a method or what?
Please select: 1 - Year 2 - Day 3 - Month Input choice: 1 Input Number: 2 I'm a Sophomore!
Please select: 1 - Year 2 - Day 3 - Month Input choice: 2 Input Number: 2 It's Tuesday.
Please select: 1 - Year 2 - Day 3 - Month Input choice: 3 Input Number: 2 February. Heart's month!
Here is my code, I only typed the Year(levels) yet because when I tried to input 2(day) and 3(month) for the Input choice and after that, Inputting a number to 1-4 would yield the same result to case 1's year levels.
#include <stdio.h> #include <conio.h> using namespace std;
[Code].....
how to link the case 2 to days and case 3 to months?