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;

const char* twenty[20] = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"

[Code] ......

View 7 Replies


ADVERTISEMENT

C :: Possible To Set Questions And System Will Randomly Display Each

Aug 5, 2014

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?

View 10 Replies View Related

Visual C++ :: Display Arrays Using Call Statements

Oct 21, 2014

I am trying to display the following arrays.

int a[4]={5,9,2,10}
int b[3][3]={1,2,3,4,5,6,7,8,9}
int c[2][3][2]={1,2,3,4,5,6,7,8,9,10,11,12}

Using these call statements

Display (a,4);
Display(b,3);
Display(c,2);

I'm not sure on how to put this all together but this is what I have so far.

Code:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
} int a[4] = {5,9,2,10};
Display(a, 4);

[Code] .....

View 4 Replies View Related

C++ :: Farm Program - Display Characteristics Of Selected Animal

Oct 12, 2014

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.

View 1 Replies View Related

C Sharp :: Retrieve Records Between Dates Selected From Datetimepicker And Of Selected Date

Mar 4, 2013

I want to retrieve the records selected between from_dt and to_dt and also the records of the selected date should be retrieved...

SELECT ChallanDtl.chalID, ChallanDtl.chalTo, 
ChallanDtl.chalNo, ChallanDtl.chalDDate,
ChallanDtl.chalYourNo, ChallanDtl.chalPO_NO, 
ChallanDtl.chalPO_Date, 
ChallanSubDtl.chalsubdescription, 

[Code] ...

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..

View 2 Replies View Related

C++ :: How To Get Rid Of Negative Number From Randomly Generated Numbers

Oct 21, 2013

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.

View 3 Replies View Related

C/C++ :: How To Get Total Number Of Items Selected From Options Menu

Jul 28, 2014

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").

View 1 Replies View Related

C Sharp :: If Checkboxlist Is Not Selected Show Save As Number 0 In DB

Sep 26, 2012

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.

protected void ckblProblemas_SelectedIndexChanged(object sender, EventArgs e){
int problemas = 0; {
if (ckblProblemas.SelectedValue.Equals("9")) {
                    problemas = 9;
                } else {
                    problemas.Equals("0");
                }

View 2 Replies View Related

C++ :: Getting Multiple Objects To Move Randomly At A Designated Number Of Intervals

Jan 9, 2015

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.

#include <ctime>
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
#include<vector>

using namespace std;

double dist(int a, int b);
int X(int x1, int x2);
int Y(int y1, int y1);

[Code] ....

View 4 Replies View Related

C++ :: Display Negative Number?

Mar 12, 2014

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.

View 7 Replies View Related

C++ :: Program To Display Even Number From 100 - 200

Jan 23, 2014

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

#include<iostream>
#include<conio.h>
using namespace std;
void main(){
for(int a=100;a<200;a++){
if(a%2=0)
cout<<a<<endl;
}
_getch();
}

View 1 Replies View Related

C/C++ :: Display Given Number With Commas

Aug 12, 2013

C program I am making.

For example: if nNum is 12345, the program should display 12,345

View 2 Replies View Related

C++ :: Reading A Number And Display In Words

Feb 5, 2015

I trying to write a program able to read a number up to 3 digits and display it in words. What to do first.

View 1 Replies View Related

C++ :: How To Display Number Of Variables / Character

Feb 13, 2013

how can i display the number of variables or character that the user input?

View 4 Replies View Related

C# :: How To Display Input Number Of Asterisks

Nov 14, 2014

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)

[Code]...

View 2 Replies View Related

C :: User Input 6 - Array To Display Even Number From 0 - 6

Apr 5, 2013

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;

[Code] .....

View 1 Replies View Related

C++ :: Display Actual Number Without Leading Zeros

Jan 20, 2014

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;

View 6 Replies View Related

C/C++ :: Display Number Of Comparisons Using Binary Search

Apr 23, 2015

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[]);

[Code] .....

View 1 Replies View Related

C :: Program That Will Generate But Not Display Three-digit Target Number

Oct 6, 2014

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).

View 8 Replies View Related

C :: Read 15 Numbers And Display Each Number On Separate Line

Oct 21, 2014

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"

View 6 Replies View Related

C/C++ :: Input Hex Number / Convert To Char And Display To Monitor

Sep 9, 2014

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;
}

View 1 Replies View Related

Visual C++ :: Nim Project - Not Displaying Matches But Display Correct Number

Apr 9, 2013

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.

[Code] ....

I will attach my code as well.ProjectNim.cpp

View 7 Replies View Related

C++ :: Array Searching - Display Highest And Lowest Number From User Input

Aug 26, 2013

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;

[Code] .....

View 2 Replies View Related

C# :: Calculating Averages - Display Employee Number And Average Of Three Test Grades

May 3, 2015

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:

132475.889.392.3
435686.383.498.3
479090.177.376.9
839373.976.389.3
556397.378.478.9
832987.365.377.2
271767.989.379.3

ReadData will have one argument, the scoresArray.

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.

Student #Test1Test2Test3Average
132475.889.392.385.8
etc, etc

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?

View 2 Replies View Related

C/C++ :: If Else Statements Being Ignored

Feb 7, 2015

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;

[Code] ....

View 2 Replies View Related

C :: Boolean Value Use For If And Else Statements

Apr 20, 2013

Am i using boolean values correctly? our professor wanted boolean value use for the if and else statements.

Code:
#include <stdio.h>
#include <math.h>
#define GRAVITY 9.8
#define LIMIT 500
#define SEC 5

[Code] ....

View 2 Replies View Related







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