Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

helloooooaaa

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;
}

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

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.

Name: Anonymous 2011-10-09 16:40

Try using curly brackets.

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.

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.

Name: Anonymous 2011-10-09 17:16

cout

GET OUT!

Name: Anonymous 2011-10-09 18:41

>>7

C OUT

Name: Anonymous 2011-10-09 19:20

IHBT

Name: Anonymous 2011-10-09 20:41

>>1
>>What am I doing wrong here?

Not using x86 Assembly

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.

Name: Anonymous 2011-10-09 22:55

>>11
your a shit cunt

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());

Name: Anonymous 2011-10-10 2:21

>>13
You forgot the import statements, the function declaration and various block parens. One line my ass.

Name: Anonymous 2011-10-10 2:36

>>14
You forgot the namespace and class declarations.

Name: Anonymous 2011-10-10 4:08

>>13

My eyes are fucking burning.

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.

Name: Anonymous 2011-10-10 5:36

>>14
C# programs need neither classes nor namespaces.

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));}

Name: Anonymous 2011-10-10 6:40

>>19
>void main

Name: Anonymous 2011-10-10 7:58

>>16
You're a pussy. That's no more uglier than a C one liner.

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?

Name: Anonymous 2011-10-10 9:13

>>20
double main(void){return (double)(int)(&main);}

Don't change these.
Name: Email:
Entire Thread Thread List