Click here to Skip to main content
15,902,735 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
double x = 0;
    double total = 0;
  
    cout << "Enter a number to add.  Enter -1 to end: ";       // priming read
    cin >> x;
  
    while( x > -1)                             
    {
      
        total += x;


What I have tried:

double x = 0;
    double total = 0;
  
    cout << "Enter a number to add.  Enter -1 to end: ";       // priming read
    cin >> x;
  
    while( x > -1)                             
    {
      
        total += x;
 does anybody know what comes next?
Posted
Updated 29-Oct-22 23:19pm
Comments
Dave Kreskowiak 30-Oct-22 0:21am    
No. You haven't said anything about what is expected of the code, so it's pretty much impossible for anyone to say anything about it.
Richard MacCutchan 30-Oct-22 4:16am    
Yes, you probably need to close the while loop, and print the total.
Member 15813072 30-Oct-22 12:36pm    
Thank you this was the only actual helpful reply
Richard MacCutchan 30-Oct-22 12:43pm    
The posted solutions were also helpful as they gave good advice. In future please provide proper details of your problem so we can understand what you are trying to do.

There are a couple of things you need to think about here:

1) Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?
That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!
We have no idea what your assignment is: and there is no master list of homework tasks which are given out to students one after the other: each teacher sets his or her own! So dumping part of an app on us asking "what code comes next?" is meaningless - we couldn't help if we wanted to!

2) While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
It's kind of strange that your program suddenly ends in the middle and you have no idea how to continue. Obviously the while loop should read values until the termination condition is reached. Since there is no counting, only the sum can be printed afterwards, but e.g. no mean value. The missing code is so trivial that you should write it yourself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900