Guys help me please, the equation on 2/3 is giving the waterTemp to 0; how come it is not changing? and also, if the nWaterTemp reached 20.00or somewhere 20.00 to 21.00; it is supposed to print that "THe kettle is now on "Help please

#include<stdio.h>
#include<stdlib.h>
#include<cstdlib>
#include<time.h>


void wait ( int seconds ){
	clock_t endwait;
	endwait = clock () + seconds * CLOCKS_PER_SEC ;
	while (clock() < endwait) {
	}
}

void behaviourOn(){

	double nWaterTemp = 0;
	int counter = 0;
 
	while(nWaterTemp <=100.0){
		counter++;
		printf("Ticking! %d\n",counter);
		wait(1);
		if(nWaterTemp >=20.0 && counter%2==0){
			nWaterTemp+=0.75;  
            	printf("The water temp is %f\n",nWaterTemp);  
		}else if(counter%3==0){
			nWaterTemp+=2/3;
				printf("The water temp is %f\n",nWaterTemp);
		}else if(nWaterTemp >=20 &&  nWaterTemp< 21){
              printf("On");
              }
	}
}


int main(void){
	behaviourOn();
	system("pause");	
}

Recommended Answers

All 3 Replies

2/3 equals zero because they're integers. Try using 2.0/3.0

2/3 equals zero because they're integers. Try using 2.0/3.0

okay done, how about the printing of "ON" it should be only printed once?

else if(nWaterTemp >=20 &&  nWaterTemp< 21 && haveNotSaidOnYet){
              printf("On");
              haveNotSaidOnYet = 0;
              }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.