d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Can Someone Help Plz
Add Reply New Topic New Poll
Member
Posts: 12,565
Joined: Dec 29 2007
Gold: Locked
Oct 29 2012 08:49pm
e/
ok i am trying to get use to C++ and make a basic calculater program
heres code


Code
#include <iostream>

using namespace std;

int main()
{

   int a;
   int b;
   int c;
   int sum;

   sum = a + b + c;
   cout << "enter a number \n";
   cin >> a;

   cout << "enter another  number \n";
   cin >> b;
   cout << "enter another  number\n" << b;
   cin >> c;

   cout << "your answer is" << sum;

   return (0);

}


when i put the numbers it keep doing 177xxxx even it it is 1+1+1

This post was edited by clanwkya on Oct 29 2012 08:52pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Oct 29 2012 10:29pm
you are trying to add uninitialized numbers. an uninitialized integer us usually the maximum integer size which is like 2,147,483,647 for a signed integer.

to fix this code move your sum = xxx statement below all your cin statements and above your cout statement printing sum
Member
Posts: 12,565
Joined: Dec 29 2007
Gold: Locked
Oct 30 2012 12:41am
Quote (AbDuCt @ Oct 30 2012 12:29am)
you are trying to add uninitialized numbers. an uninitialized integer us usually the maximum integer size which is like 2,147,483,647 for a signed integer.

to fix this code move your sum = xxx statement below all your cin statements and above your cout statement printing sum


ok thank you its working now
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll