C++ :: If Statements - Display Randomly Selected Number For 20
Jun 4, 2014
IF statement. Really new, so this will be simple I'm sure. I'm essentially just trying to roll a 6 and 20 sided die. I want the statement to run "If 20,then display the randomly selected number for 20".
// auto dice roller
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
I want to create a word game using c. My question is it possible to set questions and the system will randomly display each? If yes, what's the right code?
I need to make a program using public and private classes. I need to make a farm of five animals using the class Animal and the class has to contain charactaristics about animals i.e. speech or number of legs. So when I run the program it should output a number set to each animal and then it would display the characteristics of the selected animal.
I am not getting all the records.... when i select the same date in both datetimepicker no record is displayed... i also want the record of the selected dates from both datetime picker..
I have a error with one of my programs. I'm supposed to get rid of negative numbers when there are numbers that are randomly generated. Here is the middle part of the code.
{ int vectorLength = 10; vector<int> bothSigns(vectorLength); cout << " Input vector: "; for (int i = 0; i < vectorLength; i = i + 1) { bothSigns[i] = rand()%201 - 100;
[code] .....
The part where i'm supposed to start is after the /////'s. However, whenever I input a number for the random numbers(not put in part of code), i keep getting a segmentation error.
My project is to make a options menu for the user to select a shape and than draw out the shape. That whole process is already done and ready to go. What i am having trouble on is totaling the number of selected shapes. For example, at the end of the program i need to prompt a message saying ("You have selected "shape" this many times "number").
I'm working in a web aplication in c#, vs 2008, framework 3.5, I need to assign a value to a var, in this case "problemas", when I tried to save the value that I have in the checkboxlist, it does, but if don't selected, can't show 0, besides if I change the value "problemas = 9" to problemas = 111111" doesn't works.
I have a piece of code which gets multiple objects to move randomly at a designated number of intervals. I want to create a function which calculates the distance between each pair of points after that number of steps. so the distance between object 1 and object 2, object 1 and object 3, ..., object 1 and object N. then object 2 and object 3, object 2 and object 4, ..., object 2 and object N. then then object 3 and object 4, object 3 and object 5, ..., object 3 and object N and so on until the distance between all the pairs of points have been calculated.
I am getting strings from an HTTP request that will have hex values and I must convert those strings to a signed decimal.
//typical string inside response: //0E1D052BFBB711C1002C0042007A014DFE44022B270F7FFF8000000000000000 //every 4 characters above are a signed decimal value for (a = 0; a <= 63; a+=4){ sprintf(vval,"0X%c%c%c%c",response[a],response[a+1],response[a+2],response[a+3]); ds = strtol(vval, NULL, 16); sprintf(vval,"%d",ds); }
The problem is I never see a negative number. Decoding 0x8000 gives me 32768 but not -32768.
i wrote this program to display even number from 100-200. But visual c gives me this error with undeling the "a" in if statement. Error1error C2106: '=' : left operand must be l-value
I have been stuck at a dead end,I got it to display a single asterik for an inputted number, but how would i go about in adding that asterik for each number?
my code is the following
int userinput = int.Parse(InputOutput.GetInput("Enter values into array")); Int32[] inputChoices = new Int32[9]; for (int x = 0; x < inputChoices.Length; x++) { inputChoices[x] = 0; } if (userinput == 1)
If the user puts in a 6. I need the array to display the even number from 0 - 6. Right now what it does is it displays the first six even numbers. Okay as I'm writing this I'm starting to see where my problem might be..
Code: void sumIntegers () { int arr[50]; int i = 0; int num = 0; int sum = 0;
With the loop below, is there a way to display the actual number without the leading zeros (scientific notation) or will it just display 0 since there are so many leading zeros?
num = 1; while (num > 0){ num /= 2; } cout << num;
My assignment is "Search Benchmarks: Write a program that has a sorted array of at least 20 integers. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that uses the binary search algorithm to locate the same value. It should also keep count of the number of comparisons it makes. Display these values on the screen."
I'm unsure how to make it show the number of comparisons it takes to find the value for the binarySearch function. Also, where to put the selectionSort function the teacher said we need. This is what I have...
#include <iostream> using namespace std; int linearSearch(const int a[], int num); int binarySearch(const int a[], int num); void selectionSort(int a[]);
Write a program that will generate, but not display, a three-digit "target" number that has three distinct digits. (Hint: use random number generator.) Then, input a maximum of ten user guesses and for each guess, output the number of hits and matches in the guess. Stop when the user guesses the number or runs out of guesses. For example, if the target is 427, the guess 207 has one hit (7) and one match (2).
Program to read in 15 numbers and display them as follows //each number on a separate line
Code:
# include <stdio.h> # define MY_ARRAY 15 int main(){ int i ; printf("please enter 15 numbers
[Code] ....
Error that i get from compiler: Error E2062 array1.c 14: Invalid indirection in function main() Error E2062 array1.c 19: Invalid indirection in function main() both pointing to the separate "scanf"
What I'm trying to do is have the user input a hex number this number will then be converted to a char and displayed to the monitor this will continue until an EOF is encountered.I have the opposite of this code done which converts a char to a hex number. The problem I'm running into is how do i get a hex number from the user I used getchar() for the char2hex program. Is there any similar function for hex numbers?
this is the code for the char2hex program
#include <stdio.h> int main(void) { char myChar; int counter = 0; while(EOF != (myChar = getchar())) { if (myChar == '')
[Code] .....
This is what i want to the program to do except it would do this continuously
#include<stdio.h> int main() { char myChar; printf("Enter any hex number: "); scanf("%x",&myChar); printf("Equivalent Char is: %c",myChar); system("pause"); return 0; }
I am having one issue with my project. We are making a game of Nim code.I'm 99% done with it, i worked hard on it and i feel like i did a good job, however my project is not displaying the matches i want. For example, it display's the inital number of them 23. But once the first player subtracts a number, it doesn't display matches for player 2, just the number of matches remaining. Then as i keep running the program the same thing happens. This is what it's supposed to output:
"Input/Output sample WELCOME TO NIM ------- -- --- Enter the starting player's name (no spaces)-->John Enter the second player's name (no spaces)-->Mary There are 23 matches. ooooooooooooooooooooooo ||||||||||||||||||||||| Player John please enter the number of matches to remove-->2 There are 21 matches. ooooooooooooooooooooo ||||||||||||||||||||| Player Mary please enter the number of matches to remove-->3 There are 18 matches. oooooooooooooooooo |||||||||||||||||| Player John please enter the number of matches to remove-->1 "
This is entire code.
#include <iostream> #include <string> using namespace std; int main() { // Holds variables.
I am having a problem printing out the results for my code, It is supposed to print out the largest and smallest value in the array, but keeps giving me a value not entered and I don't know why.
//This program lets the user enter 10 numbers and then display the highest and lowest number.
#include <iostream> #include<stdio.h> using namespace std; int main() { const int NUM_ENTERED = 9; int number[NUM_ENTERED], highestValue = number[0], lowestValue = number[0], count=0;
I have a project that I am working on and I have gotten stuck. I am getting a couple errors and would like to see how I can complete the program. Not very long of a program at that. My instructions are:
Write a program to calculate averages. Create a method named ReadData that will load a two dimensional array, named scoresArray, with the following data from a file:
Create a method named DisplayAverages that will display the emplyee number (number starting 1324, 4356 etc) and the average of the three test grades. DisplayAverages will have one argument, the scoresArray. Your output should closely resemble the following.
Round averages to one decimal place. Passing arguments is important for this program. No global variables are allowed, except for the streamReader and the streamWriter. The scoresArray must be declared in Main and passed as an argument to the methods ReadData and DisplayAverages.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using LibUtil; using System.IO; using System.Text.RegularExpressions;
[Code] ....
When I run the following just to see where I am getting I get the following error:
UsersJoeDocumentsVisual Studio 2013ProjectsCIS110Program12Program12Prog ram12Dat.txt was opened Unhandled Exception: System.IndexOutOfRangeException: Index was outside the boun ds of the array. at Program12.Program.ReadData(Double[,] scoresArray) in c:UsersJoeDocument sVisual Studio 2013ProjectsCIS110Program12Program12Program.cs:line 66 at Program12.Program.Main() in c:UsersJoeDocumentsVisual Studio 2013Proj ectsCIS110Program12Program12Program.cs:line 24 Press any key to continue . . .
What am I missing here? I believe I have passed the arguments properly, but I am unable to declair the array within the bounds of the array?
My problem is that some of my conditions are not being triggered when the price level of a medium or large discount is smaller than the cost of the widget(defined as .40) An example being ,base price, $2 med discount 80%, and large discount 90%. My med discount is,1.6(80%) off of 2, so $.40, which is fine, but 90% off mean 1.8(90%) off of a base of $2, which is $.20 which is too low., and should trigger the 4th if statement, Nick you are discounting large purchases too much!. However when I run this in the program, I am triggering the first if statement.
#include <math.h> #include <stdio.h> #define widget_cost 0.40 int main (){ float sellprice; float discount_med_price;