Search code examples
c++loopsdev-c++

Create a loop that will output all the multiples of 5 that are greater than zero and less than 60 (do not include 60)


This is an assignment I have due Monday and the teacher won't email me back. My code works but it keeps showing 0 as a result and I don't know why and every time I try to fix it, the entire thing breaks. The instructions are: Create a loop that will output all the multiples of 5 that are greater than zero and less than 60 (do not include 60). This is the code that works.

#include <stdio.h>
int main(void){
 int multiples, count;
 multiples = 5;
 count = 0;

while (count < 60){
    printf("%i \n", count);
    count = multiples + count;
    if (count)
}
system("pause");

I genuinely don't get what I'm doing wrong here. I get that I can't just do (count < 60 && count > 0) because I've made the count = 0 but I need to get rid of the resulting 0 preferably without rewriting my entire code.


Solution

  • Just don't start with 0, and it's better, to exactly multiply

    #include <stdio.h>
    int main(void){
    int multiplier, count, value;
    multiplier = 5;
    count = 1;
    
    do {
        value = count * multiplier;
        count++;
        printf("%i \n", value);
    } while (value < 60)
    system("pause");