By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

Help in Adding (C++)

P: 40
Expand|Select|Wrap|Line Numbers
  1. cout<<"Enter a number: ";
  2. cin>>x;
  3. for(y=1;y<=x;y++){
  4.     cout<<"No."<<y<<": ";
  5.     cin>>no; 
  6.                 sum=no+sum;
  7. }
There's something wrong with my program..This is my desired output:
Enter no: 3
No 1: 2
No. 2: 3
No. 3: 4
Sum = 9

Please help. Thanx...
Mar 8 '07 #1
Share this Question
Share on Google+
1 Reply


P: 94
There's something wrong with my program..This is my desired output:
Enter no: 3
No 1: 2
No. 2: 3
No. 3: 4
Sum = 9
Expand|Select|Wrap|Line Numbers
  1. cin>>x;
  2. int sum = 0;
  3. for(y=1;y<=x;y++){
  4.     cout<<"No."<<y<<": ";
  5.     cin>>no; 
  6.                 sum=no+sum;
  7. }
  8. cout << "Sum = " << sum;
  9. initialize sum as 0
  10.  
  11.  
Mar 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.