C/C++ :: Adding Integer To Variable
Oct 10, 2014In my program I'm trying to add 200 to the variable named "gold". I thought this would work, but I guess it's not:
int gold2=gold+200;
int gold=gold2;
In my program I'm trying to add 200 to the variable named "gold". I thought this would work, but I guess it's not:
int gold2=gold+200;
int gold=gold2;
string str = "sfsdfsd"
and i want to add like str[3]+str[4]
but it return some integer value
I am currently working on a program that uses a class to store integer arrays. I have most of the code done, but I am having trouble on the main.cpp part of my program. The program should display this:
OBJ 1:
2 3 4
OBJ 2:
1 4 -2
Addition:
OBJ 1 =
3 7 6
Subtraction:
OBJ 1 = 1 -1 6
But when I run and compile my program, this is what I get:
OBJ 1:
2 3 4
OBJ 2:
ADDING:
OBJ 1 =
4 6 8
Subtraction:
OBJ 1 =
Here is my current main.cpp:
Code:
#include <iostream>
#include "SafeArray.h"
using namespace std;
[Code].....
I am trying to add data from a file that would go into a class that would later go into a vector of a class. I'm not really sure how to do it exactly. Here is the code:
Champion_Info.h
#ifndef CHAMPION_INFO_H_INCLUDED
#define CHAMPION_INFO_H_INCLUDED
#include <vector>
#include <string>
using namespace std;
class Champ_Info {
[Code] .....
I want define Variable that has all amount of between two integer example: 2-4
View 1 Replies View RelatedConsider the below initialization of x.
int x = 0x01234567;
If x is stored in RAM as given below, what would be the address x in both case?
(if image is invisible please follow this link)
Assume that size of integer is 4 byte.
this program is not giving to chance to enter the ooplevel value.
Code:
#include <iostream>
using namespace std;
const int SLEN = 30;
struct student {
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
// getinfo() has two arguments: a pointer to the first element of
// an array of student structures and an int representing the
[Code]...
I intend to reference this thread from another thread so I do not clutter that thread with code
/* This code is relied on by some of the functions I will post */
typedef unsigned long long zxumax;
typedef signed long long zxsmax;
[Code]....
I need to create a stack with the container being an unsigned int. I tried to put in numbers up to four bits each and have the program read the numbers individually. This is the code I am using:
void push(int n)//item n is pushed onto the stack, throw exception on full stack {
string str="Error";
if (isFull())
throw str;
[Code] ....
When I have tested it, the program is reading the numbers as one whole number. For example, I put in the number 2, and it displays the number 2. Then I put in 2 again, but this time it displays the number 10, instead of 2 2.
I already have the standard one that mimics the one taught in schools written but I've found that there is a faster formula that can be used however I not sure how to implement this. The formula is called the "Fast Fourier Transform", any simplistic example using this function base:
typedef unsigned int uint;
typedef unsigned char uchr;
uint umul( uint* src, uint val ) {
uint des = *src;
[Code] ....
If you're doing the buffer based functions then I have some pre-made functions you may need. [URL]
How can I use an integer variable in a http command example:
int num, canal;
for (num =0, num < 10, num++){
canal = num;
system( "wget http:'/'/192.168.3.4/channel.cgi?channel= canal");
}
On a controlled buffer of unsigned char it is possible to do subtraction faster than if you followed standard mathematical rules, here is an example:
typedef unsigned char uchr;
uchr num1 = 5; //00000101
uchr num2 = 3; //00000011
num2 = ~num2; // 11111100
++num2; // 11111101
uchr num3 = num1 + num2; // 00000010(2) - computer truncates result to fit char
Since you will be working with a buffer you don't even need to worry about truncating the final bit because the add function will not be able to reach it - unless it is given the ability to grow the buffer in which case you just set the bit to 0 yourself
In the code below:
void test(int * i) {
i = new int;
*i = 10;
cout << "i: " << *i << endl;
[Code] ....
The outuput is:
i: 10
t: (some memory position).
If I really want to allocate an integer variable to t, i need to modify the void test(int * i) procedure to void test(int *& i).
What I'm trying to do is to assign the length of a string to an integer variable. This is what i tried, it did not work.
Code:
printf("Enter a string
");
fgets(test_pass, 30, stdin);
strcpy(x,(strlen(test_pass)));
printf("%d", x);
This was just a test, and it did not compile. How to do this?
what I need is to get the first integer from a file and assign it to a variable and the others integers to an array. Example: Thats my file content 5 4 6 7 8 0 and that would be the code:
Code:
struct Array{
int n;
int *v;
}
[code]....
I am trying to make sure no floating point numbers can be input at any time in my roulette program. My code is too long to put in one post so I shall piece it out
#include <iostream>
#include <iomanip>
#include <random>
#include <cstdlib>
#include <ctime>
using namespace std;
// structure of arrays to pass to functions
[Code] .....
I need to average integer measuring samples and store this variable, so that it can`t be changed.
I need to get the initial pressure reading from my bmp085 pressure sensor, an integer value between 0 and 10000 and store the initial value after program start, so I can compare the later readings to determine whether pressure went down or up. The value to store should also be integer, rounding errors don`t matter.
I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:
cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {
[Code] ....
I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.
My intent was to convert the string variable for the year to an integer data type. The code compiles but now cannot run on my system. I'm not sure what's going as to what the program is displaying.
Objective: Prompt the user for two years. Print all Comedy movies that were released between those two years.
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
struct Movie {
string name;
[Code] .....
How can i write a function that will read an "unsigned integer" into a variable of type "unsigned short int"? i can not use cin >> inside the function.. so i am looking for atleast a hint!
View 16 Replies View RelatedI am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet
Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}
The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.
changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).
View 4 Replies View RelatedComplete the function myitohex so that its converts 8-byte integer to string based hexadecimals.
Ex: printf("0x%s",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}
I wrote:
#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';
[Code] ....
0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?
I would like to convert a float or double variable into unsigned char variable and back.
float number_float = 23.453f;
unsigned char* number_char = (unsigned char*)malloc(sizeof(float));
number_char = reinterpret_cast<unsigned char*> (&number_float);
float* number_float_0 = reinterpret_cast<float*>(&number_char);
I am not getting the same value back.. why?
I am having trouble compiling my interface. I am trying to store a reference variable as a member variable of the interface object. Compiler says that the variable has not be initiated correctly.
LCD inherits from VisualInterface which is expecting a DisplayDriver object to be passed in (DisplayDriver is another interface, but thats not important).
I pass the displayDriver object in when LCD is instantiated in maininterfaces.zip
I was pasing it before as a pointer but was told that this could cause me problems with memory leaks and a reference was better, but now I cant seem to get it to compile.
This problem is best explained by looking at its output below. I stored 15 different values but when retrieved some are wrong.
#include <iostream>
using namespace std;
class A {
public:
int ** pointer;
[Code] ....
I need to store and retrieve the 15 different values correctly. How to solve this? The main thing is, I need to store the pointer in class A objects.