anyone know how to write a program

HELP me please
to solve this problem using if statement

Write a C++ programme that reads a sequence of integers terminated by zero value then finds the percentage of the negative numbers and the percentage of the positive number in the sequence. The programme output is as shown: :

Enter a sequence of in integers terminated by zero

6 -7 -8 10 -12 14 15 2 -6
So what have you learnt in the last 4 days?
http://www.cplusplus.com/forum/general/245999/

Anything at all?

Like say
- read just one integer and print it out?
- read 10 integers, and print them out?
- read sequence of integers terminated by zero?

Focus on small steps which get you moving towards a goal.
Learn something and write it yourself.

http://www.cplusplus.com/doc/tutorial/control/
Before thinking about writing code try to think of the logic.

What are your inputs?
-> Sequence of characters which are terminated by zero

What is the interpretation of that? You must keep inputting a numbers until that number which was recently read in is a 0. So in the essence, you stop input if you read a 0 from input.

Now how would you do that? A for loop maybe? And when must the loop stop?

What are you outputs?
-> Percentage of positive numbers and percentage of negative numbers.

How do you calculate percentage? Percentage is (fraction x 100). What is the fraction here?
(No. of positive numbers/ total numbers) is the fraction.

Likewise can we use the same thing for negative numbers?

Okay so we've got all of that figured out.. but how to know if a number is a negative number of a positive number!?
Imagine a number line. What is to the left of 0 and what is to the right of 0? Are the numbers to the left of zero greater in value than zero or lesser?

Think for a moment and tell us what you can come up with. We will definitely help if you get it wrong.
If you are not able to come up with anything then you need to see more sample programs till where you have learnt. That could be conditionals or looping.
Last edited on
please I need answer still don't get it
Okay then break it into smaller assignments.

First make a do-while (your preference as to which loop to use) that would keep taking integer inputs until it reads in a 0.

Here is the basic structure:

DECLARE vector of integer. OR DECLARE int inputs[100] (use vector if you have learnt about it)
DECLARE i = 0;
DECLARE VARIABLE FOR INPUT

do {

-> TAKE INPUT and store in declared variable (how to take input?)
if(INPUT = 0) (is the condition in correct syntax?)
then:- BREAK LOOP (which control statement is used for this?)
Otherwise:- (what do we use to represent an 'otherwise'?)
do:- inputs[i] = INPUT

now:-
INCREMENT i BY ONE (how to do this with unary increment?)

} while ( no condition is necessary here because of the break statement but if you don't mention break then you must write INPUT != 0 over here, or write that here anyway for clarity).


Fill in the blanks.



please I need answer still don't get it
Show us your work. What have you done?

Programming is like football. The only way to learn it is to practice doing it.
closed account (E0p9LyTq)
anyone know how to write a program

Writing a program is easy.

1
2
3
4
5
6
#include <iostream>

int main()
{
   std::cout << "Do your own work!!!!\n";
}
Topic archived. No new replies allowed.