Question

I am having trouble figuring out what should go in the place of "number" to make...

I am having trouble figuring out what should go in the place of "number" to make the loop stop as soon as they enter the value they put in for the "count" input. I am also having trouble nesting a do while loop into the original while loop (if that is even what I am supposed to do to get the program to keep going if the user wants to enter more numbers???) I have inserted the question below, as well as my coding.

Question:  

In this program you will calculate a sum of numbers that are entered by the user. This program should use while loops and do-while loops to accomplish several tasks (DO NOT USE A FOR LOOP FOR THIS ASSIGNMENT).

  • After displaying a welcome screen, ask the user how many numbers they would like to add together. (*This number will be used to display the index of each number received from the user. ie. Enter Number 1: X …. Enter Number 2: X ….)
  • Using a while loop, allow the user to enter each number, keeping the total and displaying the count as they are entered (shown above).
  • Once the user has entered all of their numbers, display the final sum of their input.
  • After displaying the sum, ask the user if they would like to sum up another set of numbers by entering ‘Y’ for Yes or any other letter for No.
  • If they choose Yes, repeat the program. If they choose No, display a message stating that the program will end and end the program.

My Coding:

// This is a program that will perform calculations based on user input
#include <iostream>
#include <iomanip>


using namespace std;

int main()
{

int count; // Total amount of numbers to add together
int number; // user's number input
int total = 0; // Accumulator
char Y;
char N;
char answer; // Y or N to keep adding numbers


while (number <= count)
{
cout << "Welcome to the SUM Program!" << endl;
cout << "" << endl;
cout << "How many numbers would you like to add together?" << endl;
cin >> count; // Amount of numbers they want to add
cout << "Enter your numbers below." << endl;
cout << "" << endl;
cout << "Enter Number: " << endl;
cin >> number;
number++;
}

do
{
cout << "The sum of all your numbers is " << total << endl;
cout << "" << endl;
cout << "Would you like to find the sum of a new set of numbers?" << endl;
cout << "Enter Y for Yes and N for No." << endl;
cin >> answer;
}

while (answer == N)

{
cout << "" << endl;
cout << "Thanks for using the SUM program! Goodbye!" << endl;
}

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Program:

#include <iostream>
using namespace std;
int main()
{
/* 'sum' is for storing the sum of numbers, 'n' is for total number of integers,
'num' is for storing the current number, 'i' is the counter variable */
int sum,n,num,i;
char answer; /* 'answer' is for storing 'Y' or 'y' */
do /* do-while loop starts here */
{
   cout<<"Welcome to the SUM Program!"<<endl;
   cout<<"how many numbers you would like to add together? ";
   cin>>n; /* reads the number of integers into 'n' */
   cout<<"Enter your numbers below"<<endl;
   i=1; /* initialising 'i' by 1 (first number) */
   sum=0; /* 'sum' has the initial value 0 */
   while(i<=n) /* when i<=n, while loop repeats */
   {
       cout<<"Enter Number "<<i<<":";
       cin>>num; /* reading the current number into 'num' */
       sum=sum+num; /* calculating the 'sum', by adding the current 'num' to previous 'sum' */+
       i++; /* increments 'i' (next number) */
   }
   cout<<"The sum of all your numbers is "<<sum<<endl; /* displaying 'sum' */
   cout<<"Would you like to find the sum of a new set of numbers?"<<endl;
   cout<<"Enter Y for Yes and N for No"<<endl;
   cin>>answer; /* taking a character into 'answer' */
}while(answer=='Y'||answer=='y'); /* if 'answer' has the value 'Y' or 'y', do-while loop repeats, otherwise jump the loop */
cout<<"Thanks for using the SUM program! Goodbye!"<<endl;
return 0;
}

Program Screenshot:

Output:

Add a comment
Know the answer?
Add Answer to:
I am having trouble figuring out what should go in the place of "number" to make...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • Here is what i have so far... However i am having a little bit of trouble...

    Here is what i have so far... However i am having a little bit of trouble with it. when inputting a number the sum comes out perfect but when i break the digits up i cant do mmore than 4 digits and i cant do a negitive number... someone help. QUESTION: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example,...

  • #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers)...

    #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers) { cin>>num; if(num < 0) { moreNumbers=false; } else { count = count+1; sum=sum+num; } } avg=sum/count; cout<<"Average grade:"<<avg<<endl; cout<<"How many grades were entered:"<<count<<endl; return 0; } Question: We need to add another loop to check input. Just like the input loop we already have, this one should use a boolean variable as a control. So, the logic could be something like this: Loop...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Question 2: This program continue asking for a new number until the user enters a 0...

    Question 2: This program continue asking for a new number until the user enters a 0 to terminate the program #include <iostream.h> using namespace std; int main(void) {         int x;         int count = 0;   // (1) initialize a counter to 0 to count number of values         int choice = 1; // This is the choice that controls the looping continuation or termination         double sum = 0; // initialize the sum to 0 to make sure the...

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • Hello i am having a bit of trouble with a verified exit for my program. For...

    Hello i am having a bit of trouble with a verified exit for my program. For some reason when trying to exit it loops to the team selection function? C++ Visual Studio 2017 #include "cPlayer.h" char chChoice1 = ' '; char chChoice3 = ' '; cPlayer::cPlayer() { } cPlayer::~cPlayer() { } void cPlayer::fMenu() {    char chChoice3 = ' ';    do    {        cout << "\n\t--Menu--" << endl;        cout << "1) Enter Player Name" <<...

  • c++ I am suppose to write a function that gets a number from a user, say...

    c++ I am suppose to write a function that gets a number from a user, say 3.123456789 and then the program gets another number from the user which is used to find out how many decimal digits we want rounded to. So if the user inputs 3 then the number would turn into 3.123 then we are suppose to add two digits next to the rounded number so it would turn into 3.12300. the rounding is suppose to be done...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT