#include <ctime>
using namespace std;
int main()
{
//Array processing
int info[5][2]; //Array with 10 elements
int amt, amto, amtt, amtr, amtv;
int x=0; //counter
int y; //number of elements in array
int value=0; //input value
int total=0; //total
float average; //average
int stop=0;
cout<<"\nThis program will calculate the average of up to 10 numbers\n";
while(value!=-1)
{
cout<<"Enter sales ID number: ";
cin>>value;
if (value=1)
{
cout<<"Enter sales amount: ";
cin>>amto;
)
else if (value=2)
{
cout<<"Enter sales amount: ";
cin>>amtt;
)
else if (value=3)
{
cout<<"Enter sales amount: ";
cin>>amtr;
)
else if (value=4)
{
cout<<"Enter sales amount: ";
cin>>amtf;
)
else if (value=5)
{
cout<<"Enter sales amount: ";
cin>>amtv;
}
}
There's more stuff after it, but this is what's important.
I keep getting these errors.
"27 expected primary-expression before ')' token "
"27 expected `;' before ')' token "
Can anyone help me!?
Name:
Anonymous2007-04-12 8:59 ID:/L93LvWT
I have #include <iostream> included BTW.
It didn't get added in for some reason.
Name:
Anonymous2007-04-12 9:16 ID:9ZVtLX07
Because you need to learn how to program. PROTIP: learn the difference between the assignment operator and the comparison operator.
Name:
Anonymous2007-04-12 9:20 ID:ZfGvvdcs
You have some closing parentheses instead of closing braces in the if/else if blocks. You also want to be using == instead of = in those conditionals.
Name:
Anonymous2007-04-12 10:15 ID:aBlaFiRp
You have a lexical error at character 1:1.
HTH.
Name:
Anonymous2007-04-12 10:19 ID:4Ex0ibUn
Because you're a fucking idiot who can't solve his own compile-time problems in a drop dead simple application?
Name:
Anonymous2007-04-12 10:43 ID:f5bFH34t
>>6
Is that even relevant to the topic, or is it just your way of saying "Ive read SICP"?
Name:
Anonymous2007-04-12 10:52 ID:m05CT5uG
I AM AN EXPERT PROGRAMMER, AND THIS IS A SHITTY PROGRAM.
if/switch blocks like that usually mean you need to use an array instead.
Name:
firemasterx2007-04-12 12:26 ID:Sxm2cDyQ
yeah you have several ) where you need }
And as someone else mentioned using an array would greatly improve the speed of the program.
Good luck learning how to program :)
Name:
Anonymous2007-04-12 16:49 ID:4iT9TaWa
I hear Comp Sci 100 has TAs now.
Name:
Anonymous2007-04-12 20:02 ID:flELbtd6
Here's a classic C++ nub programmer, he can't solve his shitty program.
1) Learn C before C++(It makes C++ programmers less retarded)
2) Learn to read
3) Learn how to program
4) Learn the difference between {} and ()
5) Learn the difference between assignement and comparison operator
6) Become a hero
7) Do a barrel roll
8) Learn Java
9) ????
10) Profit
Here you go.
Name:
Anonymous2007-04-12 21:07 ID:4Ex0ibUn
>>12
Learn C before C++? Are you retarded? If he done that we'd have him not defining functions before invoking them, abusing the preprocessor, flooding the global namespace with identifiers and other such things.
Truth is if C programmers compiled their code with a C++ compiler they'd be better off anyways. They could even make use of several language constructs like enumerated constants, namespaces, constant variable declarations, etc. to make their job easier on themselves. Note those are all abstract constructs that when compiled will not "slow down their code."
Name:
Anonymous2007-04-12 22:52 ID:f5bFH34t
>>13
>Truth is if C programmers compiled their code with a C++ compiler they'd be better off anyways.
more like
Truth is if C programmers compiled their code with a C++ compiler they'd be WRITING C++.
and from the eyes of a C++ coder, thats obviously "Better"
if you had a less clouded judgement you would see that C and C++ are BOTH shit, and C++ is actually more bloated and awful than _even_ C!
>>13
I've never done C++, but I can tell you right now. In C, you declare your functions first. Failure to do so is an implicit definition, and if you're decent enough to use -Wall, you'd know this.
Ok, forgive me, I don't code in C so I was mistaken. You DO have to declare a function before use, however you don't have to give your prototype a parameter list. This compiles perfectly:
void fourchan();
int main()
{
int dickNipples;
fourchan(dickNipples);
return 0;
}
void fourchan(int pDickNipples)
{
}
And because of this feature alone C DOESN'T and CAN'T have function polymorphism.
void fourchan();
void fourchan(char shit);
int main()
{
int dickNipples;
fourchan(dickNipples);
fourchan('&');
return 0;
}
void fourchan(int pDickNipples)
{
}
void fourchan(char pShit)
{
}
This isn't even mentioning how you C fags reinvent the wheel everytime you pass a structure pointer to a function, forgetting that classes in C++ could easily do that job for you and take away the unnecessary micro-management.
Unless you're in driver or kernel development you have no fucking reason to code in C.
>>14
You're a dumbass but I'll bite. No, you're not coding in C++ unless you use C++ constructs. C++ was made to be [largely] backwards compatible with C, blah blah blah, buy more ram. Forced indentation of code, thread over.
And bloated? I dare you look into how classes actually look once compiled. Many contructs in C++ are just meant to be a concept for abstraction, meaning they don't actually "become" code. I'm just saying that many C developers would find it easier if they ran their code through a C++ compiler and -maybe- use a few of the features provided since C++'s tighter restrictions will undoubtedly fix many of the bugs before they happen.
Name:
Anonymous2007-04-13 10:35 ID:t9NZtfrS
>>18
Also forgot to say that, alas, all that is rendered null and void once once you compare C# to C++.
Name:
Anonymous2007-04-13 10:51 ID:+S2wV2Rt
In C an empty parameter list means that the parameters are unknown, in C++ an empty parameter list is the same as void; no parameters. Regardless, not properly prototyping your functions before use is really bad practice and I've never seen anyone doing it. Use of void main () and casting malloc() is a lot more frequent.
Name:
Anonymous2007-04-13 10:51 ID:qMx9jK30
function prototype declarations are optional.
Name:
Anonymous2007-04-13 11:20 ID:t9NZtfrS
>>21
int main()
{
int dickNipples;
fourchan(dickNipples);
return 0;
}
void fourchan(int pDickNipples)
{
}
Try to compile that, I dare you. Your compiler will divide by zero and time will stop.
Name:
Anonymous2007-04-13 11:20 ID:3zrnLa3f
Why is it bad practice to not prototype functions?
Name:
Anonymous2007-04-13 11:26 ID:t9NZtfrS
>>23
For starters if someone were to read your code later on the parameter lists wouldn't be explicitly known.
Name:
Anonymous2007-04-13 13:00 ID:qMx9jK30
void fourchan(int pDickNipples)
{
}
int main()
{
int dickNipples;
fourchan(dickNipples);
return 0;
}
now compile
Name:
Anonymous2007-04-13 13:05 ID:qMx9jK30
>>22
oh, and you might want to learn hugarian, that should be void fourchan(int p_nDickNipples)
>>23
Readability, and for things like the above code won't compile unless the function in declared before the main
And if you're separating your shit into .h and .cpp classes, which you should be, the .h has the class structure, members, and prototypes. The .cpp has the function implementations.
Name:
Anonymous2007-04-13 13:11 ID:+S2wV2Rt
If you don't prototype a function the compiler will construct one based on the first call it find to it. Why is that bad? Say you have a function which takes an int and you pass it a short as an argument. This is perfectly ok, the short will be promoted to an int. However, if you don't have it prototyped the compiler will assume that the function takes a short as an argument and then when it find the definition of the function which says it takes an int an error will be generated, since the arguments don't match.
Name:
Anonymous2007-04-13 14:16 ID:9NPog4e5
>>18
The reason that C accepts empty parameter lists in function declarators is to maintain compatibility with legacy code. This is how functions were written in K&R C. If you are writing C code with empty parameter lists, then you are following a convention that has been obsolete since 1989.
Polymorphic behaviour can be achieved in C, although it may not appear to be what you think polymorphism is. Here is a simple example.
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int multiply(int a, int b) {
return a * b;
}
int main(void) {
int (*op)(int, int);
op = add;
printf("op(3, 5) = %d\n", op(3, 5));
op = multiply;
printf("op(3, 5) = %d\n", op(3, 5));
return 0;
}
There is no objective reason to use one language over the other. A choice between them is nothing but a personal preference.
multiply :: Int -> Int -> Int
multiply a b = a * b;
main :: IO ()
main = do
f <- newIORef undefined;
writeIORef f add;
readIORef f >>=
print . flip ($ 3) 5;
writeIORef f multiply;
readIORef f >>=
print . flip ($ 3) 5;
Name:
Anonymous2007-04-13 15:45 ID:qrKtl5Dl
mapM_ (print . flip uncurry (3, 5)) [(+), (*)]
Pointless code FTW.
Name:
Anonymous2007-04-13 16:05 ID:3kfSoQEI
>>35 add a b = a + b;
multiply a b = a * b;
I have two questions:
1. What's with the semicolons?
2. Why did you even bother writing those functions?
>>41
If it weren't for the fact that your ID starts with WET your post would be completely pointless.
Name:
Anonymous2007-04-13 18:07 ID:lUVVwEoC
That's what happen when you don't learn C and learn C++, you look retarded like >>1,13,18,23 they use C++ because they are too retarded to understand pointers correctly and most of them know less about OO than C programmers. The only reason why they want to learn C++ is BECAUSE THBT THAT HL2 WAS CODED IN C++ SO THEY DON'T KNOW A SHIT ABOUT PROGRAMMING BUT THEY WANT TO LEARN C++ BECAUSE THEY WANT TO BE A 1337 GAEM PROGRAMMERZZ AND THEN THEY EXPECT TO BE ABLE TO CODE HL3 AND THEN THEY ARE TOLD THAT C++ IS A SUPERSET OF C SO THEY THINK THAT C IS OLD AND USELESS TO LEARN EVEN THOUGH IT'S BETTER TO LEARN C TO UNDERSTAND POINTERS AND HOW TO NOT CODE LIKE A RETARDED DUDE AND UNDERSTAND WHY SOME THINGS ARE "CONSIDERED HARMFUL" BUT BECAUSE THEY LEARN C++ THEY DON'T UNDERSTAND SOME THINGS AND AFTER THEY HAVE LEARNED HOW TO USE cout AND cin THEY THINK THEY KNOW EVERYTHING BUT WHEN THEY WILL BE TALKING WITH NOT RETARDED C++ PROGRAMMERS THEY WILL GET FLAMED BECAUSE THEY PRETEND TO PROGRAM IN C++ EVEN THOUGH THEY DON'T KNOW A SHIT ABOUT OO.
>>44
Wow, that's quite a broad generalization for a language with such a large developer base. And honestly, you're not special for understanding pointers. We all know you just learned about pointers last week but please, shut your mouth about it.
Do you care to point out how I, >>18, am wrong and you are so very right? Did I hurt your feelings?
What's funny with your post is that most C programmers I know are just too damn lazy to learn anything -beyond- C. They just picked out the thinnest programming book at the store that they could find, read it a few times and spend the rest of their time telling programmers of other languages how great they are in comparison and jerking eachother off in their respective forums.
Name:
Anonymous2007-04-13 21:56 ID:lUVVwEoC
DEAR >>45, DID I HURT YOUR FEELINGS ?!!?!?!!1611ONEONEONESIXSIXONE
I THINK YOU DON'T UNDERSTAND THAT I WAS TROLLING.
What's funny with your post is that most C programmers I know are just too damn lazy to learn anything -beyond- C.
WHAT'S FUNNY WITH YOUR POST IS THAT MOST C++ PROGRAMMERS I KNOW ARE JUST TOO DAMN LAZY TO LEARN ANYTHING -BEYOND- cout AND cin.
Time to stop trolling now.
First of all even if it looked like I was generalizing, I was not. But theres a lot of people who program in C++ because they know that lots of games have been programmed in C++ and they pretend to program in C++ even though the only thing they know is cout and cin without any clue about what OO is and they don't stop talking shit about "THEIR NEXT MMORPG" I was talking about them. I know that most of C++ programmers are competant etc.
We all know you just learned about pointers last week but please, shut your mouth about it.
No, sir. BTW, I trolled about that because you said : This isn't even mentioning how you C fags reinvent the wheel everytime you pass a structure pointer to a function, forgetting that classes in C++ could easily do that job for you and take away the unnecessary micro-management.
If you call that reinventing the wheel there's a problem, BTW WELCOME TO PROCEDURAL PROGRAMMING WHERE METHODS DON'T EXIST, SIR. IT'S AN OLD AND DIFFERENT WAY TO PROGRAM GET USED TO IT. They just picked out the thinnest programming book at the store that they could find, read it a few times and spend the rest of their time telling programmers of other languages how great they are in comparison and jerking eachother off in their respective forums.
SAME THING WITH C++ PROGRAMMERS SIR
and that's because C programmers like to troll.
What's funny with your post is that most C programmers I know are just too damn lazy to learn anything -beyond- C.
It hurted my feelings, seriously, don't you think it's the same with C++ programmers ?
I didn't say that I don't program in C++ and I don't think I lack of knowledge in programming because I learned a lot "beyond" C
I still think what I said when I wrote >>44 but I explained my point this time.
Name:
Anonymous2007-04-13 23:22 ID:ZABjT4TH
>>18,45
HEY GUYS I CAN'T EVEN WRITE VALID C CODE BUT I WILL GLADLY LECTURE YOU ON WHY C IS INFERIOR
>>49
I TRIED TO USE MISMATCHING FUNCTION DECLARATIONS AND IT DIDN'T WORK THEREFORE C DOES NOT HAVE POLYMORPHISM
Name:
Anonymous2007-04-14 1:35 ID:ypZA+b2l
Could be that you need to get your vision checked.
Name:
Anonymous2007-04-14 1:41 ID:GGjiw6Q6
>>52
Uhm, fucking exactly? And it never will in any future revision due to the retarded rule that states you don't have to give a parameter list when defining a function.
Name:
Anonymous2007-04-14 4:29 ID:AWcLfLYl
The lack of polymorphism in C is the deal breaker for me. I'm fine with pointers and even manual memory management (though I don't approve of lowering myself to doing work that the computer should be doing for me) but writing a sort function for arrays of ints and then having to copypasta to have the same code work for floats is lame.
>>56
Then you have to cast the return value, and how is your program supposed to know what to cast it to? Fag.
Name:
Anonymous2007-04-14 8:47 ID:4vxCuLuE
>>57
...
Your program is obviously not supposed to know what to cast it to, it's your job.
OH HO, IT'S SO BORING TO WRITE (cast) EACH TIME I CALL THE FUNCTION
Name:
Anonymous2007-04-14 9:14 ID:AWcLfLYl
>>58
Right numbnuts, so when I write my sort function to take an additional argument f, a function to compare two items, how is sort() supposed to know the type of f() when the whole point is that it could be any type because we're trying to make the damn thing polymorphic?
>>62
Take a look at the ugly "polymorphism" example in C using a function pointer a while ago, it's laughable.
And you can be sure that the C programmers will come up with some ugly "template" hack in C trying to prove you wrong.
Name:
Anonymous2007-04-14 13:03 ID:sTxSa6if
Is it possible to do something like writing an animal class and derive it to several other classes like bird, mammal, whatever and save all those classes in a container in c? Just wondering how you do that in c.
Name:
Anonymous2007-04-14 13:24 ID:K1dwZ0tN
>>64
WELCOME TO PROCEDURAL PROGRAMMING WHERE INHERITANCE DOESN'T EXIST, SIR. IT'S AN OLD AND DIFFERENT WAY TO PROGRAM GET USED TO IT.
Name:
Anonymous2007-04-14 13:42 ID:xEaotdBm
>>61
A low-level language like C or FORTRAN is also necessary for applications that need as much performance as they can get, such as scientific simulations to be run on large parallel computers.
Name:
Anonymous2007-04-14 13:43 ID:CCHJWxso
>>65
>WELCOME TO PROCEDURAL PROGRAMMING WHERE INHERITANCE DOESN'T EXIST, SIR. IT'S AN OLD AND DIFFERENT WAY TO PROGRAM KERNELS AND WRITE DEVICE DRIVERS GET USED TO IT. C WAS ONCE MADE TO BE A PORTABLE ASSEMBLY. ONE OF THE GOALS OF C++ WAS TO BE A BETTER C, LEARN C++ INSTEAD EVEN IF YOU AREN'T GOING TO USE THE ADDED FEATURES.
Fixed it for you.
>>67 WELCOME TO PROCEDURAL PROGRAMMING WHERE INHERITANCE DOESN'T EXIST, SIR. IT'S AN OLD AND DIFFERENT WAY TO PROGRAM GET USED TO IT. C WAS ONCE MADE TO BE A PORTABLE ASSEMBLY. ONE OF THE GOALS OF C++ WAS TO TOTALLY MISUNDERSTAND THE CONCEPT OF OBJECT-ORIENTATION, BOLT IT ON TO C AND FOOL THOUSANDS OF IDIOTS INTO ACTUALLY USING IT, LEARN HASKELL INSTEAD.
Fixed some grammatical mistakes.
Name:
Anonymous2007-04-14 13:52 ID:K1dwZ0tN
>>67
It's funny to see how C++ fags think that C++ is superior to C and don't understand that a decent programmer should learn both
Name:
Anonymous2007-04-14 14:02 ID:CCHJWxso
>>70
It's funny how C programmers think everyone should learn C and give no fucking reason as to why.
>>71
Hi. I'm not a C programmer, I'm a Haskell fag. Everyone should learn C because it's really fucking widespread. If you do any nontrivial coding, you're deemed to come across some C code. If you don't know how to hack it, you're fucked.
Name:
Anonymous2007-04-14 14:17 ID:CK5pKzjY
You two are missing the point that both C and C++ are made of lose and fail. I challenge any of you faggots to implement y f = f (y f) in your retarded language.
Name:
Anonymous2007-04-14 14:23 ID:vdOUtjPl
>>40
Hai dumbass, I was merely proving they're optional. I would never go with out them, though.
>>74
Optional but you could never use them outside the narrow scope of that example, so you fail.
Name:
Anonymous2007-04-14 14:43 ID:Op3SamSC
You're are missing the point that Haskell is made of lose and fail. I challenge any of you faggots to implement an operating system in that retarded language.
>>91
Don't hold your breath. It's surely possible but very ugly. On the other hand an Y combinator is more of a party trick than a real programmingg problem.
>>96
I know that but anyone saying that he uses it all the time rings my bell. I've had some use for that once or twice during the 15 years I've programmed. Maybe I just suck cocks.