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
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).
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 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;
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;
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[]);
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?
Write a program that displays the first 40 Fibonacci numbers. A Fibonacci number is created by add the previous two, with the first two always being 0 and 1. A partial sequence is as follows:
0, 1, 1, 2, 3, 5, 8, 13, 21,….
Your table must display 6 numbers per row and use a spacing of 10 for each number. Don’t forget to include the header file “iomanip” at the top and use “setw()”. You will need to turn in an algorithm, source code and output.
Here is what i have but i get errors!
#include <iostream> using namespace std; { int FirstNumber = 0; int SecondNumber = 1; int NumberOfNumbers = 2; int NewNumber;
Also is there a way to display the time only instead of the date? How will i change the program to display the time in standard 12 hours, instead of 24 hours?
#include <iostream> #include <time.h> using namespace std; int main() { time_t tim; time(&tim); cout << ctime(&tim); }
Write a program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, so:
(Calories from fat) = (fat grams) * 9
The percentage of calories from fat can be calculated as:
(Calories from fat) / (total calories)
Extend as follow
1. The user first enters from a menu whether it is breakfast (B or b), lunch (L or l) or dinner (D or d). Use character and process by a switch. 2. The threshold for low calorie is different, for breakfast 10%, lunch 20%, dinner 30% (this value has to be assigned to some threshold variable in the above switch). 3. Include validation of menu choice. 4. In case any validation fails, display detailed error and exit the program by calling return 1 or return EXIT_FAILURE 5. Display the % from fat with one decimal digit.
Example 1: What you have to eat: B - breakfast L - lunch D - dinner What you have: C Error: C is not a valid menu choice
Example 2: What you have to eat: B - breakfast L - lunch D - dinner What you have: L How many calories: 600 How many grams of fat: 10 Your food has 15.0% calories from fat It is a low calories food
Process the menu in a switch, setting the threshold as either 10, 20, or 30%. The rest of the program will be the same regardless what was the menu choice.
Incremental development: first do the textbook problem without input validation, then extend with validation, then extend for the additional parts.
IM trying to make a simple program that will display morse code. Ex if you type 0 print should be (-----) and all the way up to 5. The problem is though that all printf displays all the numbers and not executing only the assigned variable.
#include<stdio.h> int main(void) { int a , b , c , d , e, f, x;