Professional Documents
Culture Documents
Looping
Namiq Sultan
University of Duhok
Department of Electrical and Computer Engineerin
• ++ and -- are operators that add and subtract one from their
operands.
num = num + 1;
num += 1;
num++;
a = 2;
b = 5;
c = a * b++;
cout << a << " " << b << " " << c;
Results: 2 6 10
x = 10;
if ( x++ > 10)
cout << "x is greater than 10.\n";
cout << "How many students do you have test scores for? ";
cin >> numStudents;
cout << "Enter the scores for each of the students.\n";
Student 1: 75 80 82 [Enter]
The average is 79.
Student 2: 85 85 90 [Enter]
The average is 86.67.
Student 3: 60 75 88 [Enter]
The average is 74.33.
do{
statement;
Statement(s)
statement;
. . .
expn
}while(expression); True
False
#include <iostream>
#include <cstdlib> // for srand() function
#include <ctime> // for time() function
using namespace std;
int main()
{ int a;
srand(time(0));
for(int i=0; i<10; i++)
cout<<rand()/1000<<" ";
return 0;
}
int main()
{
int numStudents, numTests, total, score;;
float average;
cout << "This program averages test scores.\n";
cout << "For how many students do you have scores? ";
cin >> numStudents;
cout << "How many test scores does each student have? ";
cin >> numTests;
5. Write a program that reads a set of numbers, and adds them together. The
program is terminated when the user inputs 0. Then the result of added
numbers is printed out.