-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhileLoop.cpp
118 lines (96 loc) · 1.92 KB
/
whileLoop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
using namespace std;
int main()
{
int i=0;
for(;; )
{
cout<<"Hello\n";
i++;
if(i%2 != 0)
continue;
cout<<"a\n";
cout<<"b\n";
if(i>=10)
break;
}
// int numb = 99, sum = 0;
// while(numb != 0)
// {
// cout<<"Enter a number(0 to terminate): ";
// cin>>numb;
// sum += numb;
// }
//
// cout<<"sum = "<<sum<<endl;
//Swapping values
// int a = 2, b = 5;
// cout<<"a = "<<a<<"\tb = "<<b<<endl;
// int temp;
// temp = a;
// a = b;
// b = temp;
// cout<<"a = "<<a<<"\tb = "<<b<<endl;
//Fibonnaci Series
// unsigned int first = 0, second = 1;
// unsigned int sum;
// int total;
// cout<<"Enter number of terms of the series: ";
// cin>>total;
// cout<<"Enter the first term of series: ";
// cin>>first;
// cout<<"Enter second term of series: ";
// cin>>second;
// int i = 3;
// cout<<first<<"\t"<<second<<"\t";
// while(i <= total)
// {
// sum = first + second;
// first = second;
// second = sum;
// cout<<sum<<"\t";
// i++;
// }
// int hours, students, total;
// float avg;
// cout<<"How many students are there?: ";
// cin>>students;
// int i=0;
// while(i<students)
// {
// total = 0;
// int j=0;
// while(j<3)
// {
// cout<<"Hours worked by student "<<i+1<<" on Day "<<j+1<<" : ";
// cin>>hours;
// total += hours;
// j++;
// }
// avg = (float)total/3;
// cout<<"Average hours worked by Student "<<i+1<<" = "<<avg<<endl;
// i++;
// }
//
int student, hours, total;
float avg;
cout<<"Enter how many students are there: ";
cin>>student;
int a=0;
while(a<student)
{
total = 0;
int b=0;
while(b<3)
{
cout<<"Hours worked by student "<<a+1<<" on day "<<b+1<<": ";
cin>>hours;
total+=hours;
b++;
}
avg = float(total)/3;
cout<<"Average of hours spent by student "<<a+1<<" is "<<avg<<endl;
a++;
}
return 0;
}