1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
andrey2020 [161]
3 years ago
7

Write a program sum.cpp that reads a sequence of integers from cin, and reports their sum. Example If you have a file numbers.tx

t that contains:
Computers and Technology
1 answer:
Katarina [22]3 years ago
8 0

Answer:

The solution code is as follows:

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. int main()
  6. {
  7.    ifstream data;
  8.    float number;
  9.    float sum = 0;
  10.    
  11.    data.open("numbers.txt");
  12.    
  13.    while (data >> number) {
  14.        sum = sum + number;
  15.    }
  16.    cout<<sum;
  17.    return 0;
  18. }

Explanation:

Firstly, we create a ifstream object, <em>data</em> (Line 9). Then we can use the ifstream object to open the "numbers.txt" (Line 13) and use while loop to traverse through the number in the text file line by line (Line 15). White the loop is ongoing the number in each line is read by >> operator in a similar way to cin and then add each read number to sum variable (Line 16).

At last, display the output (Line 18).

You might be interested in
Mrs. Zoo gave out the rubric for our essay. She stated that our essay should be complete by Friday of that week. I didn't have t
Rom4ik [11]

Answer:

No

Explanation:

You had the whole week for the essay but didn't do it and then turned it in late.

6 0
3 years ago
Which pickaxe in minecraft to use?
Law Incorporation [45]

Answer:

Diamond pickaxe with efficiency 3

Explanation: It will mine quicker and you can just get unbreaking

6 0
3 years ago
2. Sanjay thinks it's okay to plagiarize because he thinks his instructors won't find out. However, it's
Tatiana [17]
The correct answer is B
8 0
3 years ago
Write a program that takes three numbers as input from the user, and prints the largest.
S_A_V [24]

Answer:

In Python:

n1 = int(input("Enter a number: "))

n2 = int(input("Enter a number: "))

n3 = int(input("Enter a number: "))

if n1 >= n2 and n1 >= n3:

   print("Largest: "+str(n1))

elif n2 >= n1 and n2 >= n3:

   print("Largest: "+str(n2))

else:

   print("Largest: "+str(n3))

Explanation:

The next three lines get three numbers from the user

n1 = int(input("Enter a number: "))

n2 = int(input("Enter a number: "))

n3 = int(input("Enter a number: "))

This checks if the first number is greater than the other two. If yes, the first number is printed as the largest

<em>if n1 >= n2 and n1 >= n3:</em>

<em>    print("Largest: "+str(n1))</em>

This checks if the second number is greater than the other two. If yes, the second number is printed as the largest

<em>elif n2 >= n1 and n2 >= n3:</em>

<em>    print("Largest: "+str(n2))</em>

This prints the third number as the largest, if the other two conditions fail

else:

   print("Largest: "+str(n3))

3 0
3 years ago
Read 2 more answers
What are invoices? A. Documents that convey a company's liabilities B. Documents that convey how much a company was earning and
grandymaker [24]
<span>C. Documents that convey buyers, sellers, and purchases made</span>
5 0
4 years ago
Read 2 more answers
Other questions:
  • Which field data type would you use if you'd like to store videos in that field a text b memo c Boolean D binary object E null
    11·2 answers
  • The part of the computer that provides access to the internet is the
    10·1 answer
  • What state yall be livin in?
    15·2 answers
  • Edhesive 4.1 question 1
    9·1 answer
  • What does scarcity force people to do?
    11·1 answer
  • As the first step, load the dataset from airline-safety.csv by defining the load_data function below. Have this function return
    9·1 answer
  • Match the protocols to their use. HTTP POP3 SMTP FTP You check email in your inbox. arrowRight You send an email to a friend. ar
    14·1 answer
  • Have a good christmas. this might not be homework, but i just want everyone to have a good week
    6·2 answers
  • Question 1 of 10
    9·1 answer
  • a transport layer security (tls) virtual private network (vpn) requires a remote access server listening on port 443 to encrypt
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!