Question

Week 5- Counts using While or Do-While Loop Write a program that asks the user to input 6 integer numbers, then the program c

the question just that. here is what i have done, put something wrong with it
onlinegdb.com Online Cee Com ino Courts wing While Downlop Loops - Add only proverb GDB beta debugger or CC SPONSOR monday -
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new cpp program with name "main.cpp" is created, which contains following code.

main.cpp :

//header files
#include <iostream>
using namespace std;
int main()
{
//declaring array to store integer
int intArray[6];
//declaring variables
int n,positiveCount,negativeCount,zeroCount,numberCount=0;
positiveCount=0;
negativeCount=0;
zeroCount=0;
do{
//asking user to enter integer numbr
cout<<"Enter the integer number "<<(numberCount+1)<<":";
//reading number
cin>>intArray[numberCount];
numberCount=numberCount+1;//increment numberCount
}while(numberCount<6);
numberCount=0;//reinitilizing numberCount to 0
//using while loop
while(numberCount<6)
{   
//checking each number from the array
if(intArray[numberCount]>0)
{
//if number from the array is greater than zero
positiveCount=positiveCount+1;//increase positiveCount
}
else if(intArray[numberCount]<0)
{
//if number from the array is less than zero
negativeCount=negativeCount+1;//increase negativeCount
}
else if(intArray[numberCount]==0)
{
//if number from the array is zero then
zeroCount=zeroCount+1;//increase zeroCount
}
numberCount++;//increase numberCount
}
//print details
cout<<"Positive count : "<<positiveCount<<endl;//print positve number count
cout<<"Negative count : "<<negativeCount<<endl;//print negative number count
cout<<"Zero count : "<<zeroCount<<endl;//print zero count
return 0;
}

======================================================

Output : Compile and Run main.cpp to get the screen as shown below

Screen 1 :main.cpp

input Enter the integer number 1:3 Enter the integer number 2:58 Enter the integer number 3:9 Enter the integer number 4:-1 E

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
the question just that. here is what i have done, put something wrong with it Week...
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
  • (Count positive and negative numbers and compute the average of numbers) Write a program that reads...

    (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.' *So I think my code is looping because the...

  • Question text Find four problems with this program: ------------------------------------------- using namespace std; // this program inputs...

    Question text Find four problems with this program: ------------------------------------------- using namespace std; // this program inputs three integers, determines if negative, positive, or zero int main() { cout << "Enter an integer" << endl; cin >> input;    if (input < 0); cout << "The number is negative."  endl; else if (input > 0) cout << "The number is positive" << endl; else cout << "The number is zero" << endl;    return 0; } programm c++ please and thank you

  • 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...

  • I'm not getting out put what should I do I have 3 text files which is...

    I'm not getting out put what should I do I have 3 text files which is in same folder with main program. I have attached program with it too. please help me with this. ------------------------------------------------------------------------------------ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the...

  • Here is the code I made, but the test case is not working, it goes wrong...

    Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) {        int array[16];        int i = 0;        for (int counter = 0; counter < 16; counter++)        {               array[counter] = 0;        }        while (number > 0)        {...

  • Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp...

    Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp Is posted here: // This program reads data from a file into an array. Then, it // asks the user for a number. It then compares the user number to // each element in the array, displays the array element if it is larger. // After looking at entire array, it displays the number of elements in the array larger // than the user...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  • Change your C++ average temperatures program to: In a non range-based loop Prompt the user for...

    Change your C++ average temperatures program to: In a non range-based loop Prompt the user for 5 temperatures. Store them in an array called temperatures. Use a Range-Based loop to find the average. Print the average to the console using two decimals of precision. Do not use any magic numbers. #include<iostream> using namespace std; void averageTemperature() // function definition starts here {    float avg; // variable declaration    int num,sum=0,count=0; /* 'count' is the int accumulator for number of...

  • Hello, I am working on a C++ pick 5 lottery game that gives you the option...

    Hello, I am working on a C++ pick 5 lottery game that gives you the option to play over and over. I have everything working right except that every time the game runs it generates the same winning numbers. I know this is an srand or rand problem, (at least I think it is), but I can't figure out what my mistake is. I've tried moving srand out of the loop, but I'm still getting the same random numbers every...

  • 1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately...

    1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately terminating the list reading when the sentinel value (lets use -9999) is entered. The program should then correctly report the number of non-negative scores entered and the arithmetic mean (average) of those scores 2. Demonstrate your programs behavior in response to errors on input (that is, show that it faithfully rejects improper input such as alphabetic characters, decimal points, and commas). Here are some...

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