helloooooaaa
1
Name:
Anonymous
2011-10-09 16:11
what am i doing wrong here? or am i doing anything? im trying to get the average of the given 5 numbers.
#include<iostream>
using namespace std;
int main( )
{
int x, sum, counter, sonuc;
sum = 0;
counter = 0;
cout<<"enter a number"<<endl;
cin>>x;
sum = sum + x;
counter = counter + 1;
if ( counter <= 5)
cout<<"enter another number"<<endl;
cin>>x;
else
sonuc = sum/counter;
cout<<"sonuc = ";
cout<<sonuc<<endl;
system("PAUSE");
return 0;
}
2
Name:
Anonymous
2011-10-09 16:20
well you see you are only read in a number once that you add to the sum, then you read another number in but don't do anything with it, then you exit
3
Name:
Anonymous
2011-10-09 16:27
yeah i know but compiler gives me an error like "expected primary definiton befor else" or expected ";" before else. if the program executes i will configure it furtherly but im asking you what is the syntax error? its a basic one but i have nothing to do at this moment.
4
Name:
Anonymous
2011-10-09 16:40
Try using curly brackets.
5
Name:
Anonymous
2011-10-09 17:01
what am i doing wrong here?
Using Sepples, not using code tags, putting a space between parentheses in your function header, not using += or ++, using system("PAUSE"), using namespace std;, not having main take argc and argv as arguments, not looping and having multiple statements after an if without brackets.
I probably missed a few things.
6
Name:
Anonymous
2011-10-09 17:01
>>1
Are you expecting the program to magically jump back to the
if without you using a loop? Have fun with that.
7
Name:
Anonymous
2011-10-09 17:16
cout
GET OUT!
8
Name:
Anonymous
2011-10-09 18:41
9
Name:
Anonymous
2011-10-09 19:20
I H B T
10
Name:
Anonymous
2011-10-09 20:41
>>1
>>What am I doing wrong here?
Not using x86 Assembly
11
Name:
Anonymous
2011-10-09 20:57
int sum = 0;
int x, average
int max = 5;
for (int i = 0; i < max; i++){
cout<<"Enter number: "<<endl;
cin>>x;
sum += x;
}
average = sum/max;
cout<<"Average: " + average<<endl;
Something like that. Not sure, haunt worked with cpp for a while.
12
Name:
Anonymous
2011-10-09 22:55
13
Name:
Anonymous
2011-10-10 2:04
idk, but you can do it in a single line of C#
Console.WriteLine(Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).Average());
14
Name:
Anonymous
2011-10-10 2:21
>>13
You forgot the import statements, the function declaration and various block parens. One line my ass.
15
Name:
Anonymous
2011-10-10 2:36
>>14
You forgot the namespace and class declarations.
16
Name:
Anonymous
2011-10-10 4:08
>>13
My eyes are fucking burning.
17
Name:
Anonymous
2011-10-10 5:34
You need a while loop. Also, don't use "system" anything. Just use getc or getch. Inb4 conio is evil.
18
Name:
Anonymous
2011-10-10 5:36
>>14
C# programs need neither classes nor namespaces.
19
Name:
FrozenVoid
2011-10-10 5:37
//sum command arguments
void main(int argc,char**argv){
double a=0;int c=1;while(c<argc)a+=strtod(argv[c++],NULL);
printf("\n%.16f",a/(argc-1));}
20
Name:
Anonymous
2011-10-10 6:40
21
Name:
Anonymous
2011-10-10 7:58
>>16
You're a pussy. That's no more uglier than a C one liner.
22
Name:
Anonymous
2011-10-10 8:52
>>5
What's wrong with having 'using namespace std;' and why the hell would the program take in arguments if there's no need for any?
23
Name:
Anonymous
2011-10-10 9:13
>>20
double main(void){return (double)(int)(&main);}
Newer Posts