Loops ex - C+ Repetition exercises Question 1: Write a...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Repetition exercises
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Question 1: Write a program, to enter 20 numbers: 1- Count all input numbers which are in the range 1. . 99 (inclusive). 2- Find the sum of all input numbers which are out of the previously mentioned range. 3- Display the count of (in range) numbers, and the sum of (out of range) numbers.
Background image of page 2
void main() { int count=20,inCount=0; float num,outSum=0; while (count-- > 0) { cout<< "enter a number:" ; cin>>num; if inCount++; else outSum+=num; } cout<< "count of in_range numbers is: “ <<inCount<<endl; cout<< "sum of out_of_range numbers is:” <<outSum<<endl; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Question 2: A group of "p" players are playing dice game (each player is represented by a number starting with 1), and each is allowed to roll two dices 5 times. Write a program to carry out the following tasks: 1- Calculate scores for all players and display them along with the player number. Note: The score for each player is calculated as follows: find the sum of the two dices, if the sum is greater than 6 it should be
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/12/2012 for the course IT 101 taught by Professor Fadi during the Spring '12 term at University of Damascus.

Page1 / 9

Loops ex - C+ Repetition exercises Question 1: Write a...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online