compound while statement conditions

Hello, I'm trying to write my first while code that will only spit out numbers when the "total" is positive up to a certain rage. I'm having a problem with my syntax, and was wondering if someone can tell me what im doing wrong?
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
  #include<iostream>
#include <string>
#include<iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
int number;
int count;
int total;
int max;
cout<<"input number"<<endl;
cin>>number;
cout<<"input your maximum number";
cin>>max;

count=0;
while (((count*number)<max-number) && (max>0)){
total=number*count;

cout<< total<<", ";
count=count+1;

}
if (total=max-number)

cout<<total;

}
The 'total' is uninitialized. What if the loop condition is false from start? The if on line 26 would compare uninitialized total to something.

The 'max' does not change in the loop. Therefore, the 0<max is true or false already before the loop and stays so.

The 'max-number' does not change either. You could store that in a variable to save re-evaluation.

 In function 'int main()':
26:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]

You have an assignment, not equality comparison in the if. Is that intentional?

Can you give some examples on input and expected output?
Topic archived. No new replies allowed.