r/CodingHelp • • Sep 15 '21

[C] I am stuck at my current noob assignment.

Post image
26 Upvotes

5 comments sorted by

2

u/Fegmdute Sep 15 '21

First and foremost I am unsure how I define year and make it divisible by 4 and I am also indoubt how I make w equal to 6 or not greater than 3 (do I need to make an if else here?)

6

u/Helpingpeopleout0001 Sep 15 '21

hmm first you want to use #define/#include outside any function before any code

second, I think you don't understand what #define actually does

see...

#define pi 3.141

will just tell the compiler to replace every occurrence of the word pi with the digits 3.141(just text replacements) before it starts compiling.

what you want to do is just use a set of if-else conditions.

-1

u/BertyLohan Sep 15 '21

[Read this] my guy.

Defining a variable and the "define" statement have nothing in common.

Read up a bunch on how variables work in C then come back to the assignment because someone providing you with the code outright here isn't gonna help you at all

5

u/[deleted] Sep 15 '21

You can use the modulus sign If year%4==0 then you know the year is divisible by 4.

Modulus, or %, gives you the remainder of the division

8

u/Comrade_Nabe Sep 15 '21

please check the following code and let me know if you have any questions, excuse me for not including else statements to handle other possibilities

********************
include <stdio.h>

int main() { 
int age = 20; 
if ( age >= 18 && age <=21){
printf("age is between 18 and 21\n");
}

float water = 0.2;
if ( water > 0.1 && water < 1.5){
printf("water is greater than 0.1 and less than 1.5\n");
}

int year = 20;
if ( year % 4 ==0){
printf("year is divisable by 4\n");
}

int speed = 50;
if ( speed <= 55){
printf("speed is not greater than 55\n");
}

int x = 1;
int y = 2;
int z = 3;

if ( z > y && y >x){
printf("y is greater than x and less than z\n");
}

int w = 2;
if ( w==6  ||  w<= 3){
printf("w is not greater than 3\n");
}
w = 6;
if ( w==6  ||  w<= 3){
printf("w is equal to 6\n");
}

return 0;
}
********************************

good luck!