0

Write a C++ program that adds numbers...first let the user decide on the numbers he wants to use and add them all together?

C

9th Oct 2017, 4:53 PM
kennedy
kennedy - avatar
10 odpowiedzi
+ 12
Is this what you want? #include<iostream> using namespace std; int main () { int n = 0; double num = 0.0; double sum = 0.0; cout << "How many number? "; cin >> n; for(int i = 1; i <= n; i++) { cout << "#" << i << ": "; cin >> num; sum += num; } cout << "The total is: " << sum << endl; }
9th Oct 2017, 5:08 PM
Babak
Babak - avatar
+ 12
So give me more details about what you want.
9th Oct 2017, 6:48 PM
Babak
Babak - avatar
+ 11
So, you'd prefer the output be like this? Example #1: 34 #2: 12 #3: 65 ... 34 + 12 + 65 = 111
10th Oct 2017, 6:41 AM
Babak
Babak - avatar
10th Oct 2017, 8:34 AM
Babak
Babak - avatar
+ 4
in c language #include<stdio.h> #include<conio.h> void main() { clrscr(); int n; printf("enter how many numbers u would like to add"); scanf("%d",&n); float a; float sum; int i; sum=0; for(i=1;i<=n;i++) { scanf("%d",a); sum=sum+a; } printf("the sum of all elements is %d",sum); getch(); }
10th Oct 2017, 8:40 AM
SAKSHI
SAKSHI - avatar
+ 3
sorry the above is wrong below is correct give input: 3[means no.of elements] 1 2 3[these three are the numbers u are going to add] now output will be: 1 2 3 sum of elements is :6
10th Oct 2017, 9:01 AM
SAKSHI
SAKSHI - avatar
+ 3
this one works for your question......
10th Oct 2017, 9:03 AM
SAKSHI
SAKSHI - avatar
0
no...its wrong
9th Oct 2017, 6:35 PM
kennedy
kennedy - avatar
0
okay....I want a program where me as a user I will input the number of values I want...then add each of them together to print out the sum.
10th Oct 2017, 6:36 AM
kennedy
kennedy - avatar