neovstan
Like how to use them later
You can use a number just in cycle after its getting from std::cin, but if you want to use it subsequently, you can store them all to container. E.g.:
int count{};
std::cin >> count;
std::vector<int> numbers;
for (int i = 0; i < count; ++i) {
int number{};
std::cin >> number;
numbers.push_back(number);
}
кар карыч
Thanks
neovstan
Next, you can get any value from vector numbers by this way numbers[0], numbers[1], numbers[2], etc
neovstan
Thanks
It should be understandable to you if you have ever programmed in other languages
кар карыч
and how to make a loop that will check if number[1] > S, then it adds up with number[0], and if number[1] <S, then it skips it, and so on until the last number
кар карыч
I'm sorry if I bored you)
Anonymous
how to print
кар карыч
Thx
neovstan
Thx
Be careful, the addition will be produced if each number is greater than S, but not if they're equal
neovstan
how to print
😕
#include <iostream>
int main()
{
std::cout << "Hello, world" << std::endl;
}
X
pbuf1 = (char*)VirtualAlloc(NULL, // System selects address
100, // asks for 100 bytes
MEM_COMMIT, // allocate committed memory
PAGE_READWRITE); // protection = read and write
printf("The first buffer allocated at : 0x%x\n", (DWORD)pbuf1);
while (count < 100)
*(pbuf1 + count) = 'a';
count += 1;
//allocate the second the buffer
pbuf2 = (char*)VirtualAlloc(NULL, // System selects address
100,
MEM_COMMIT,
PAGE_READWRITE);
count = 0;
printf("The second buffer allocated at: 0x%x\n", (DWORD)pbuf2);
while (count < 100)
*(pbuf2 + count) = 'b';
count += 1;
//free buffers
VirtualFree(pbuf1, 0,MEM_RELEASE);
VirtualFree(pbuf2, 0,MEM_RELEASE);
X
it does not print the second buffer ?
Anonymous
кар карыч
Anonymous
did it
neovstan
кар карыч
кар карыч
But… if I need to get the result in (sum2)
кар карыч
supposedly it should add up all the received numbers and write them down
neovstan
кар карыч
neovstan
neovstan
If you want to add only MODIFIED values, then put amount += line into if:
int amount{};
for (int i = 0; i != numbers.size(); ++i) {
if (i > 0 && numbers[i] > S) {
numbers[i] += numbers[i-1];
amount += numbers[i];
}
}
кар карыч
And the result will be written to (amount)?
кар карыч
cout << (amount)?
neovstan
ʙʀʜᴏᴏᴍ ⑇
HW_3.cpp:331:12: error: conflicting declaration 'std::string destinationFile'
331 | string destinationFile = "C++/HomeWorks/sodoku/board.txt"
| ^~~~~~~~~~~~~~~
HW_3.cpp:326:10: note: previous declaration as 'char destinationFile [256]'
326 | char destinationFile[256];
ʙʀʜᴏᴏᴍ ⑇
ʙʀʜᴏᴏᴍ ⑇
any one plz!?
Dima
you better show the whole code
ʙʀʜᴏᴏᴍ ⑇
ofstream fout;
char destinationFile[256];
string destinationFile = "C++/HomeWorks/sodoku/board.txt"
if (fout.fail())
{
cout << "Output file opening failed.\n";
exit(1);
}
else
cout << "Board written successfully";
Dima
char destinationFile[256];
string destinationFile
why and what is the reason?
Dima
you cant use duplicating variable name
Dima
error basically says the same
Dima
remove the second line
ʙʀʜᴏᴏᴍ ⑇
oh!!
I see ... my bad
ʙʀʜᴏᴏᴍ ⑇
Koorosh
hi
Koorosh
Friends who have apps are programming. I can bring the rap program to the top of the Play Store with Google Play's comment service. For service, visit Pewi.
Talula
Anonymous
how to insert graphics.h in cxxdroid
Anonymous
What's the meaning of % in coding of C
\Device\NUL
neovstan
abdullah reveha
hello i have an assigment and i am not able to create correct algorithm to solve assigment. could you help me please?
ASSIGMENT
Horizontally best fit tetris
We will ask user to how many tetrominos you will use and we will ask again which ones you will use.
According to the tetrominos we must print horizontally best-fit on the screen.
EXAMPLE OUTPUT:
How many tetrominos?
3
What are the types?
O
T
L
Horizontally best-fit tetrominos:
T
OOTT L
OOTLLL
Anonymous
\Device\NUL
Denys
Hello, l have a question about my task. I need to copy 3 elements of array of 9 elements to another and sort it. l am exactly copy elements, but l am trying to sort it and nothing happens
Denys
Hello, l have a question about my task. I need to copy 3 elements of array of 9 elements to another and sort it. l am exactly copy elements, but l am trying to sort it and nothing happens
#include <stdio.h>
int main(void)
{
int array[9] = { 50, -1, 99, 46, -4, 70, 85, 4, 10 };
int length = sizeof array / sizeof array[0];
int temp;
int i, j, k;
int array2[3];
for (i = 0; i <length; i++)
{
printf("%d ",array[i]);
}
printf("\nCopy 3 elements into array2: ");
for (i = 0; i <length-6; i++)
{
array2[i] = array[i];
printf("%d ", array2[i]);
}
for (k = 0; k < array2[i]; k++)
{
for (j = 0; j < array2[i] - 1; j++)
{
if (j > k)
{
temp = array2[k];
array2[j] = array2[k];
array2[k] = temp;
printf("%d ", array2[i]);
}
}
}
}
klimi
#include <stdio.h>
int main(void)
{
int array[9] = { 50, -1, 99, 46, -4, 70, 85, 4, 10 };
int length = sizeof array / sizeof array[0];
int temp;
int i, j, k;
int array2[3];
for (i = 0; i <length; i++)
{
printf("%d ",array[i]);
}
printf("\nCopy 3 elements into array2: ");
for (i = 0; i <length-6; i++)
{
array2[i] = array[i];
printf("%d ", array2[i]);
}
for (k = 0; k < array2[i]; k++)
{
for (j = 0; j < array2[i] - 1; j++)
{
if (j > k)
{
temp = array2[k];
array2[j] = array2[k];
array2[k] = temp;
printf("%d ", array2[i]);
}
}
}
}
> for (k = 0; k < array2[i]; k++)
what should this do?
Denys
my copying array is 50 -1 90 so when l running through array l campare the next( for (i = 0; i <length-6; i++)) and previous ( for (j = 0; j < array2[i] - 1; j++)) elements
Denys
Ilya
for (k = 0; k < array2[i]; k++)
This line is rly strange. In your example this loop will repeat 50 times
Ilya
it's like buble sort
for (k = 0; k < array2[i] here must be the length of array2, not an item in the strange position; k++)
if (j > k) - what is the point in comparing indexes? You must compare items of array
cez
excuse me all, i try to connect c++ visual studio to sql. but it fail bcs exception unhandled at memory. any idea?
Ilya
Anonymous
enum class Tetrominos {I,O,T,J,L,S,Z};
int main() {
int all_tetrominos = 3;
Tetrominos x;
cout << "What are the types?" << endl;
while(all_tetrominos>0) {
cin >> x; // problematic line
all_tetrominos--;
}
}
How can I fix this code? cin >> x; line is problematic
emiteclap
>=
Dima
bruh
JHex125
Has anyone run into a case when vector fail to initialize with given initialize value by resize? I want to know it doesn't work.
JHex125
I have a vector map and a enum class Grid, I want to initialize all the elements with map.resize(MAP_WIDTH, Grid::coin), but it doesn't work, and when I use for loop, it works.
_VVV_
Hey! Help solve problems. I using the EnumProcesses method, I got a list of processes, how can I now select system and user?
Yuvraj
has anyone given deutche bank graduate analyst oncampus test?
smene
_VVV_
olli
How to separate processes into user and system?
what do you mean by that? On Windows there is exactly one System Process, usually with ID 4.
Do you mean which processes have user mode parts? Or processes which have been started by the system?
_VVV_
_VVV_
EnumProcesses(ProcessesIDs, sizeof(ProcessesIDs), &cbNeeded);
cProcesses = cbNeeded / sizeof(DWORD);
for (i = 0; i < cProcesses; i++)
{
if (ProcessesIDs[i] != 0) {
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessesIDs[i]);
//__
HANDLE token = 0;
DWORD nlen, dlen;
TOKEN_USER* ptu;
char name[300], dom[300], tubuf[300];
int iUse;
if (NULL != hProcess)
{
GetModuleBaseName(hProcess, NULL, szProcessName, sizeof(szProcessName) / sizeof(TCHAR));
}
actualValue.insert(ProcessesIDs[i]);
OpenProcessToken(hProcess , TOKEN_QUERY, &token);
ptu = (TOKEN_USER*)tubuf;
GetTokenInformation(token, (TOKEN_INFORMATION_CLASS)1, ptu, 300, &nlen);
LookupAccountSidA(0, ptu->User.Sid, name, &nlen, dom, &dlen, (PSID_NAME_USE)&iUse);
cout << name << endl;
CloseHandle(hProcess);
}
}
_VVV_
Did not work out
Anonymous
#include <stdio.h>
#include <math.h>
int main ( ) {
int a;
printf("enter number : ");
scanf("%d \n", &a );
printf("%d \n ", a>9 && a<100);
int sum = a>9 && a<100;
return 0;
What's the error in it?
OUTPUT: I ENTER THE NUMBER BUT IT IS NOT GOING FORWARD ⏩⏩ IT JUST STOPPED WHYY?
Deepak Chaurasia