Anonymous
Yes
Then you made some other mistake like forgetting to save the file and recompiling your code again. It works fine now on my compiler. Can't help you more with this.
Dr
I'm going to go through my work again But thanks
You forgot the curly braces after if statement
Anonymous
You forgot the curly braces after if statement
The if part has only one statement inside it. So the curly braces are optional.
Dr
if(candidateX1.votes>50){ printf …. }
Dr
The if part has only one statement inside it. So the curly braces are optional.
Well I’m not sure about that because I generally put it in a curly braces
Anonymous
Well I’m not sure about that because I generally put it in a curly braces
Well it is good to do so but it is not required. His code should work as long as he corrects the problems with his scanf statements.
Nank
if(candidateX1.votes>50){ printf …. }
When it's only one instruction after the if, it's not necessary to put the curly braces
Nank
#include <stdio.h> #include "Elections.h" Candidat candidatX1, candidatX2, candidatX3, candidatX4; void infoCandidat(){ printf("Name candidat1 : "); scanf("%s", candidatX1.name); printf("Nomber of votes : "); scanf("%d", candidatX1.votes); printf("Name candidat2 : "); scanf("%s", candidatX2.name); printf("Nomber of votes : "); scanf("%d", candidatX2.votes); printf("Name candidat3 : "); scanf("%s", candidatX3.name); printf("Nomber of votes : "); scanf("%d", candidatX3.votes); printf("Name candidat4 : "); scanf("%s", candidatX4.name); printf("Nomber of votes : "); scanf("%d", candidatX4.votes); } void voteTour1(int votes[4]){ if(candidatX1.votes > 50) printf("Candidat %s, You've been elected", candidatX1.name); else if(candidatX1.votes > 12 && candidatX1.votes < 50){ printf("You've not win but you go to the second tour"); if(candidatX1.votes > candidatX2.votes && candidatX1.votes > candidatX3.votes && candidatX1.votes > candidatX4.votes) printf("Candidat %s, You're 1st in the second tour", candidatX1.name); else printf("Candidat %s, You're in the second tour but you're not the first", candidatX1.name); } else printf("OUT ! You're no more in the competition"); }
The problem was that i put "votes" as a tab. when i remove it, everything's ok now
Anonymous
Why?
Kayae
Write a C program that accepts a string of characters from a terminal and displays the string one word per line.
olli
Why?
The rules clearly state the expected behavior. This discussion is off-topic.
olli
Help me
What have you done so far? Where is your code? What's your question?
Kayae
Code for this question
olli
This
I don't see any code. Technically this is not even a question. We're happy to answer question but not to do your homework. Please read the rules.
Kayae
Ok
Kayae
How do we trace the program
Kb
Is any one good in c programing
Kb
I have Infosys 1st coding test
Anonymous
I'm stuck at a question... Can anyone help
Sid
Which question
Sid
???
Sahil
Hlo guys, Im a beginner nd I just started coding with learning c++ as first step. My problem is that I'm unable to run my code as it says like this " access is denied" . I tried to look after it on google nd YouTube though I'm unable to resolve it. Can any one help me
Sahil
How are you compiling it?
I had installed the code runner extensions
klimi
klimi
what os are you using, how do you compile and run your code
Sahil
Even for a simple hello world program neither I could compile nor I could run it
klimi
well if you can't compile it, it is expect that you won't be able to run it
klimi
what?
Dr
Windows
Which compiler are you using?
SMS
The code runner
Which IDE are you using
SMS
Is it called Visual Studio?
SMS
MSVC is your compiler
Dr
Apart from code runner it is essential to have a compiler downloaded like mingw
Dr
The code runner
Is this your first time?
Dr
So please google and install MinGW
Sahil
SMS
Yes
Is there a screenshot of the error?
Sahil
Is there a screenshot of the error?
Ya sure... Wait a minute
Pavel
What is the reason for this code not to compile? Why does it try to resolve std::to_string call before the concrete type is known? Is there a way to prevent that (like we do with .template function calls)? https://ideone.com/224VeQ
Pavel
You mean something like: if (i != j) { print(" "); } else { print(i); } ?
Pavel
Just replace i with array[i][i] in the code I've sent
Pavel
you need to add line break like you did in your code before
Peace
I am getting this error when I declare my array as int arr[size]; and apply built-in sort function on this array. error: request for member ‘begin’ in ‘arr’, which is of non-class type ‘int [size]’
Talula
I am getting this error when I declare my array as int arr[size]; and apply built-in sort function on this array. error: request for member ‘begin’ in ‘arr’, which is of non-class type ‘int [size]’
Is that in C++? And that isn't where you're getting the error, you're getting error when you're calling begin... which is normally found in Arduino programming.
Suka
if you use basic data type u can use pointer arithmetic
@omar
Hey guys can anyone help me with this? I am working on it for 2 days and can’t get the logic! So question is like this: Given a string “2Aaaa443333o#”, “2” is a run of length 1; “Aaaa” is a run of length 4. The above string has 6 runs, the length of its longest run is 4, and the number of longest runs is 2. Here, the lower and upper cases of an alphabet letter are treated as the same symbol.
@omar
So basically I have to find, these so called runs in a string. But how to separate them?
Peace
the following code is not producing output... int main(){ int size; cout<<"Enter size of array: "; cin>>size; std::vector<int> arr; for(int i=0;i<size;++i){ cin>>arr[i]; } for(int i=0;i<size;++i){ cout<<arr[i]; // no output } return 0; }
Peace
Try std::vector <int> arr(size);
that worked.. but how ! Please explain
Golden Age Of
that worked.. but how ! Please explain
Your code just declares vector, but its fully empty, and when you try to fill arr[i], it can't be filled , cuz there is nothing. And the way I show is that u create vector of the chosen size(and its assigned by zeros by default, so ur vector exists) and u just rewrite every member of ur vector
Peace
I have a function printArray(int *arr, int size); and the array is a vector . When I call the function , compiler raises error error: cannot convert ‘std::vector’ to ‘int*’ for argument ‘1’ to ‘void printArray(int*, int)’
Anonymous
Hi i have a question in C
Anonymous
This is the code: int**i, i= malloc(sizeof(int*)), if (i==NULL) **i=5, free(i)
Anonymous
I think i made a mistake in the memory mangement or 🤔
Golden Age Of
Anonymous
Just using a pointer
Nils
printArray(arr.data(), arr.size())
int printArray(const char *d, size_t s) { return write(1, d, s); }?
Anonymous
I allocated a memory area of size int for my pointer
Golden Age Of
I allocated a memory area of size int for my pointer
Why would you need a pointer to pointer?