im still new in programming ,i really hope you guys could help me to check mind ,because its always diplays 0

#include<iostream>
using namespace std;

int main()
{
float num1,num2,total,average;

cout<<"Enter two numbers:";
cin>>num1>>num2;

total:num1+num2;
cout<<"The total of the number is"<<total;

average=total/2;
cout<<"The average of the number is"<<average;
}
The problem is total:num1+num2; The assignment operator is =
This works fine: http://cpp.sh/3pjk7
OUTPUT:
Enter two numbers:3 8
The total of the number is 11
The average of the number is 5.5 

really????,i guess i have to fix my laptop
THANK YOU!!!!!
Last edited on
Why do you have to fix your laptop?

The line you provided is legal syntax, but doesn't really do anything.

total:num1+num2;

In this line "total" is just a label (because it is followed by a colon). If you added goto total; somewhere in your code, the code would jump to this line.

Your line adds together num1 and num2, but does nothing with the result. So the addition happens (unless optimized out of the code by the compiler), but nobody knows what the result was because it was never stored anywhere.

So, there is actually nothing wrong with your computer or your compiler.
becuse the result always zero ,but when thomas1965 post the link it gives result,thats why i assume my laptop problem or my apps
you are not understanding what he said. For some weird reason he put the code on a 3rd party site, and THAT version worked, not YOUR version.

your version, as already said, does NOT assign the addition into total, so total remains whatever value it had. That happened to be zero, which is often done by debug builds, but it could be anything in a release build (including zero).

just change the : to =
its just a typo that you made that happens to be legal syntax so it compiles and runs (the worst kind of typo there is!).

nothing is wrong with your laptop or phone.
Last edited on
Topic archived. No new replies allowed.