Juli
#include <iostream> #include <math.h> using namespace std; #define N 10 int main (void) { // begin of main double arrayOfIntegers[N]; double number = 0; int counter = 0; for (int i = 0; i < N; i++ ) { // for loop begins std::cout << "Please enter a positive integer number " << endl; std::cin >> number; if ( number <= 0 ) { cout << "You have entered a negative number or a zero " << endl; cout << "The program will restart " << endl; break; } else { arrayOfIntegers[i] = (double)number; counter ++; } } // for loop ends if ( counter == N ) { // if all the numbers are positive std::cout << "You have entered " << counter << " valid numbers " << endl; double sum = 0; for (int i = 0; i < N; i++ ) { // for loop begins sum = sum + arrayOfIntegers[i]; } // for loop ends double average = ((double)sum/counter); double sd = 0; for (int i = 0; i < N; i++ ) { // for loop begins sd += ( (double) (arrayOfIntegers[i] - average) * (arrayOfIntegers[i] - average) ); } // for loop ends sd = ( (double) sd/counter ); sd = sqrt ( (double) sd ); char Type = 'a'; std::cout << "Type 'a' to print average or 's' to print standard deviation" << endl; cin >> Type; Type = tolower(Type); if (Type == 'a') std::cout << "The average is: " << average << endl; else if (Type == 's') std::cout << "The standard deviation is: " << sd << endl; else std::cout << "Did not receive correct instruction" << endl; } // if all the numbers are positive else { // else if cout << "Please enter all positive integer numbers" << endl; } // else if return 0; }
Juli
#include <iostream> #include <math.h> using namespace std; #define N 10 int main (void) { // begin of main double arrayOfIntegers[N]; double number = 0; int counter = 0; for (int i = 0; i < N; i++ ) { // for loop begins std::cout << "Please enter a positive integer number " << endl; std::cin >> number; if ( number <= 0 ) { cout << "You have entered a negative number or a zero " << endl; cout << "The program will restart " << endl; break; } else { arrayOfIntegers[i] = (double)number; counter ++; } } // for loop ends if ( counter == N ) { // if all the numbers are positive std::cout << "You have entered " << counter << " valid numbers " << endl; double sum = 0; for (int i = 0; i < N; i++ ) { // for loop begins sum = sum + arrayOfIntegers[i]; } // for loop ends double average = ((double)sum/counter); double sd = 0; for (int i = 0; i < N; i++ ) { // for loop begins sd += ( (double) (arrayOfIntegers[i] - average) * (arrayOfIntegers[i] - average) ); } // for loop ends sd = ( (double) sd/counter ); sd = sqrt ( (double) sd ); char Type = 'a'; std::cout << "Type 'a' to print average or 's' to print standard deviation" << endl; cin >> Type; Type = tolower(Type); if (Type == 'a') std::cout << "The average is: " << average << endl; else if (Type == 's') std::cout << "The standard deviation is: " << sd << endl; else std::cout << "Did not receive correct instruction" << endl; } // if all the numbers are positive else { // else if cout << "Please enter all positive integer numbers" << endl; } // else if return 0; }
Strife
#include <iostream> #include <math.h> using namespace std; #define N 10 int main (void) { // begin of main double arrayOfIntegers[N]; double number = 0; int counter = 0; for (int i = 0; i < N; i++ ) { // for loop begins std::cout << "Please enter a positive integer number " << endl; std::cin >> number; if ( number <= 0 ) { cout << "You have entered a negative number or a zero " << endl; cout << "The program will restart " << endl; break; } else { arrayOfIntegers[i] = (double)number; counter ++; } } // for loop ends if ( counter == N ) { // if all the numbers are positive std::cout << "You have entered " << counter << " valid numbers " << endl; double sum = 0; for (int i = 0; i < N; i++ ) { // for loop begins sum = sum + arrayOfIntegers[i]; } // for loop ends double average = ((double)sum/counter); double sd = 0; for (int i = 0; i < N; i++ ) { // for loop begins sd += ( (double) (arrayOfIntegers[i] - average) * (arrayOfIntegers[i] - average) ); } // for loop ends sd = ( (double) sd/counter ); sd = sqrt ( (double) sd ); char Type = 'a'; std::cout << "Type 'a' to print average or 's' to print standard deviation" << endl; cin >> Type; Type = tolower(Type); if (Type == 'a') std::cout << "The average is: " << average << endl; else if (Type == 's') std::cout << "The standard deviation is: " << sd << endl; else std::cout << "Did not receive correct instruction" << endl; } // if all the numbers are positive else { // else if cout << "Please enter all positive integer numbers" << endl; } // else if return 0; }
jezz
Luca
https://pastebin.com/7ctnSWLa
Luca
I get a problem with atomic, it can't be moved or copied, how can i solve?
Azhar
*++ptr first increment of pointer and than value of that element?
Juli
Help me pls
net
https://www.reddit.com/r/cpp/comments/r7xvd1/c20_coroutine_benchmark_result_using_my_coroutine/
Danny
Good day group maybe someone to help me with a program in c ++ El consultorio del Dr. Lorenzo T. Mata Lozano Its policy is to charge for the consultation based on the appointment number, as follows: - the first three appointments to $200.00 c/u. - the following two quotes at $150.00 each. - the next three appointments at $100.00 c/u. The remaining ones to $50.00 c/u, while the treatment lasts. An algorithm is required to determine: a) how much the patient will pay for the appointment. B) the amount paid by the patient for the treatment I need to do this program but it is An end module program and I need to perform it as complex as possible to make it great thank you so much for your support
Danny
Sorry
Azhar
How to access last element of array using adress/pointer?
Azhar
How to access last element of array using adress/pointer?
https://stackoverflow.com/q/45059789/15048892
Azhar
I tried this but it giving me some random garbage adress
\Device\NUL
How to access last element of array using adress/pointer?
(ptr + sizeof(ptr) - 1) or *(ptr + sizeof(ptr) - 1)
Azhar
Array?
Nameful
What is size of here?
https://en.cppreference.com/w/cpp/language/sizeof
danya
Hello everyone, I need to find words from a file, what is the logic for this, can u tell?
Suka
Hello everyone, I need to find words from a file, what is the logic for this, can u tell?
read every line from your file and find the word than you can break or continue read and find
danya
given a lot of words that are not related to the word I need to find
Mr
Suggest me a c program to write output as 1 11 111 1111 11111
void main() // Also you can use int { int out, l, max; out=1; l=0; max=6; // How many 1 you wanted to see into last line while(l != max) { l++; printf("%d\n", out); out=(out*10)+1; } } Most Easiest Form
Ludovic 'Archivist'
Anonymous
https://pastebin.com/7ctnSWLa
You shouldn't do this. There is a reason why the standard prevents such things. If you have multiple atomic variables then you need to enforce some mechanism to synchronise changes to them. If you let them be changed independently then your invariants are going to violated which is why the standard does not allow atomics to be copied or moved. What you should do instead is declare a struct inside your class A like this struct A { bool flag; int i; }; Then you have to declare a atomic<S> var inside your class A. Given the typical sizes of bool and int on most implementations, this atomic would be lock free but you can check if it is so. Since you have not given details on why you want to do this, this is as far as I can help.
Azhar
(ptr + sizeof(ptr) - 1) or *(ptr + sizeof(ptr) - 1)
Can message you a question of allocation of memory? Im not getting
\Device\NUL
Can message you a question of allocation of memory? Im not getting
If you know how to access array with pointer or access its address with pointer than you will know how to access last element of array
Hsn
(ptr + sizeof(ptr) - 1) or *(ptr + sizeof(ptr) - 1)
Sizeof(ptr) isnt correct as far as i know. sizeof(array)/sizeof(array[0])
\Device\NUL
Sizeof(ptr) isnt correct as far as i know. sizeof(array)/sizeof(array[0])
Ah thanks, also sizeof operator didn't work for dynamic memory allocation since it's return sizeof pointer
coal
the size of ptr as a whole / the size of an individual element in ptr
coal
then just do ptr[length-1]
coal
Ah thanks, also sizeof operator didn't work for dynamic memory allocation since it's return sizeof pointer
it returns a size_t, which is an equivalent of an unsigned int/long or even long long, basically
Jobair
can you guys help me?
Jobair
#include<stdio.h> int main() { int i, n, length, width, total=0; printf("How many rooms in the house? "); scanf("%d", n); for(i=1; i<=n; i++) { printf("Please enter length and width of a room in feet: "); scanf("%d%d", &length, &width); total = total + (length*width); } printf("Total square footage = %d", total); return 0; }
Jobair
The question is: Write a C program that computes the square footage of a house given the dimensions of each room. Have the program ask the user how many rooms in the house and then request the dimensions of each room. Display the resulting total square footage.
Jobair
My code is not working
olli
How to access last element of array using adress/pointer?
you need to know the beginning of the array and the size void* getLastItemOfArray(void** Array, size_t Size) { return Array[Size - 1]; } iff you have a local static array you can use the sizeof trick, however this does not work for dynamically sized arrays or arrays passed as parameter to other functions.
coal
use %i instead of %d
coal
and separate it by space: scanf("%i %i")
coal
you can't get the size of a dynamic array
coal
you need to keep track of the size
Luiz
use %i instead of %d
what's the difference?
coal
what's the difference?
its similar, however %i also interprets the number as an hexadecimal when preceded by 0x
coal
and an octal when preceded by 0
coal
whereover %d only checks for literal digits
coal
i.e. over "031", %d would output 31, and %i would output 25
coal
i rather using %i in general because it parses the literal format instead of just the number, but thats up to your needs
danya
Can someone tell me how to add to Fputc char, if char = 12(number) and i have "<" but not 12?
coal
thought the problem was that he didnt separate the format codes either
Jobair
It works now
Jobair
I didn’t noticed actually
coal
separated or not doesn't matter
i've been doing it wrong since always then lol
Nothing
Hello everyone I'm software student in the first year I have been asked to give presentation can anyone give me idea of a topic
coal
what field do you know most about
coal
the topic should probably be something you studied already
olli
why not try running it?
\Device\NUL
it returns a size_t, which is an equivalent of an unsigned int/long or even long long, basically
char arr[100]; printf("%zu\n", sizeof(arr)); This one is expected char *arr = (char *) malloc(100 * sizeof(char)); printf("%zu\n", sizeof(arr)); This one is not
klimi
That's the whole point of pointers
coal
i didnt understand your question at first sorry
coal
you must keep the track of the array size
klimi
Only on the stack the compiler already knows its result
klimi
Malloc doesn't necessary allocate the memory
coal
hmm
coal
i think it does
klimi
Nope
coal
isnt it short for "memory allocate"