I'm taking C++ in college and my professor is foreign and can not speak English very well. He wrote all of this on the board for us to do but I'm really not sure what he wants us to do. I believe it is a few different programs. Can anyone make sense of this?
even| for (int i= 0; i <= 100; i +=2)
| {
tot t= i;
}
odd for (int i = 1; 1 <= 100; i+=2)
{
totodd +=i;
}
These are all different programs
seperate appropriately.
float ave;
int tot = 0;
int c = 0;
for (int i = 0; i <= 100; i++)
{
c++;
cout << i;
tot +=i;
}
cout << "count is # y time goes through loop = "; << c;
ave = tot/c;
do
i+=2;
while(1 <=100)
for (0;0;0;)?(not sure if this is relavent)
for (int i = 0;i<= 100; i++)
{
if (i mod2==1)
totodd+=i;
else
toteven +=i;
}
totall = totodd + toteven;
#include <iostream>
usingnamespace std;
int main()
{
float ave;
int tot = 0;
int c = 0;
for (int i = 0; i <= 100; i++)
{
c++;
cout << i << " ";
tot +=i;
}
cout << endl << "Count is # y time goes through loop = " << c;
ave = tot/c;
cout << endl << "Average is : " << ave << endl;
}
The forth caculates the total of even numbers less than or equal 100 ,the total of odd numbers <= 100 ,then calculates the sum of both totals
#include <iostream>
usingnamespace std;
int main()
{
/*he shows you another way to do one of the above
do
i+=2;
while(1 <=100)*/
/*Dont be surprised this one is correcte too
for (0;0;0)
cout << "hello" << endl;*/
int totall,totodd,toteven;
for(int i = 0;i<= 100; i++)
{
if (i%2==1)
totodd += i;
else
toteven +=i;
}
totall = totodd + toteven;
cout << "The total of the odds and evens is : " << totall << endl;
}
the professor made a mistake somewhere. It looks like he wants to get an average of user inputs. Something like:
1 2 3 4 5 6 7 8 9 10 11
double sum = 0;
unsigned count = 0;
double n;
while (cin >> n)
{
sum += n;
count++;
}
cout << "The average of all inputs is " << (sum / count) << ".\n";