So this code is suppose to print out the results of 0*1, 1*2, 2*3, 3*4, 4*5, 5*6, 6*7, 7*8, 8*9, and 9*10. It prints out the number 0 and thats it. Any help. Do I have the order wrong? I have tried x++ and y++ as well and same result.
1 2 3 4 5 6 7 8 9 10 11 12 13
int x = 0;
int y = 1;
int z ;
while (z<=90);
{
z= x*y;
cout << z << "," ;
++x;
++y;
}
cout << endl;
(Please make sure you put entire compilable code in - including the main statement and the headers).
Problem 1 - you don't initialise z. So what is it supposed to be in line 5 when you compare it with 90?
Problem 2 - your while loop starts on line 5 ... and ENDS on line 5, because you have a semicolon at the end of it; remove this semicolon. The next block of code, enclosed in braces, won't loop until you do.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
usingnamespace std;
/**
*
*
* @creator
*/
int main(int, char**) {
// part 1 of part 0
int i;
for(i=2; i<=20; i+=2)
{
cout << i << ",";
}
cout<< endl ;
// part 2 of part 0
int n = 17;
do
{
cout << n << "," ;
n = n-2 ;
} while(n>=1);
cout << endl ;
// part 3 of part 0
int x = 0;
int y = 1;
int z = 0;
while (z<90)
{
z= x*y;
cout << z << "," ;
x++;
y++;
}
cout << endl;
cout << endl;
//part 1 of 1
int m;
for(m=10; m<=95; m+=5)
{
cout << m << " " ;
if (m % 8 == 5) cout << endl;
}
cout << endl;