can you please show me how to make a countdown timer?
and a game program, like guess the missing word. because when i tried it, it doesn't give the right output. please help me. because i really don't know much about c++ i might fail to this subject.:S:'(

Recommended Answers

All 14 Replies

Show us what you tried, so we can make corrections and give you some suggestions on how to improve your code.

If you post the code you have tried to make then we can see what the errors are.

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int word, a, perfume;

	
	cout<<"Singing bee game./nGuess the missing word for phrase."<<endl;
	cout<<"Are you ready?/nset/nStart!"<<endl;

	cout<<"it's four am and i'm waking up to your _______"<<endl;
	cout<<"what is the missing word to complete the phrase?"<<endl;
	cin>>word;

	a=perfume;

	if (word == a)
	{
		cout<<"Correct answer!/nYou can now proceed to the next song."<<endl;
	}
	else
	{
		cout<<"Wrong answer!/nSorry, try again next time :P"<<endl;
	}

	return 0;

}

this is what i did
and i don't know how can i put the timer.

sorry for the late reply.huhu

int is a number, not word. Instead use std::string.

/n <-- this is one main problem! it should be \n which is new line.

change "int" into char or sting

int word, a, perfume;

These variable are used for numbers :

int word, a, perfume;

What you need to use is something that can handle words, like std::string;

string word, a, perfume;

Also I notice that "a" variable, is the correct word that you are trying to compare in this statement :

if (word == a)

That means that you should initialize "a" variable to something like so:

string a = "room"; //correct answer
string word, perfume;

Also it would be better if your variable name is not "a". Give it something more meaningful like correctAnswer;

Here is a complete program , which is the same as yours but with my suggestion incorporated.

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string userInput;
	string correctAnswer = "room";

	
	cout<<"Singing bee game.\nGuess the missing word for phrase."<<endl;
	cout<<"Are you ready?\nset\nStart!"<<endl;

	cout<<"it's four am and i'm waking up to your _______"<<endl;
	cout<<"what is the missing word to complete the phrase?"<<endl;
	cin>> userInput;


	if(userInput == correctAnswer)
	{
		cout<<"Correct answer!\nYou can now proceed to the next song."<<endl;
	}
	else //incorrect answer
	{
		cout<<"Wrong answer!/nSorry, try again next time :P"<<endl;
	}

	return 0;

}

Also I am not sure if its supposed to be case insensitive or not, but it is in the above program.

tnx a lot.
uhm..
how can i put a timer in this program?
what is the syntax for a countdown timer?

To use timer, you need to use the clock function. Maybe this example will help you :

#include <iostream>
#include <ctime> //for clock()

using namespace std;

bool myPrint()
{
	static int cnt = 10;
	cout << cnt << "!\n";
	cnt--;

	if(cnt <= 0)
		return false; //stop at 0

	return true;
}
int main()
{	
	//convert our starting time to seconds
	unsigned int clk_strt = clock()/CLOCKS_PER_SEC; 
 
	unsigned int UPDATE_TIME = 1; //update every 1 seconds

	while(true)
	{		
		unsigned int clk_end = clock()/CLOCKS_PER_SEC;
		//if the difference in the time we started
		//and the current time is greater than our 
		//UPDATE_TIME, which is 1 second then ...
		if(clk_end - clk_strt >= UPDATE_TIME)
		{
			//reset time
			clk_strt = clk_end;
			//count down
			if( myPrint()== false){
				cout<<"!!!BOOM!!!\n";
				break;			
			}
		}		
	}


	
	return 0;

}

tnx a lot. u really help me guys.
i really appreciated it.

how can i put this in the application?

tnx a lot.
bt how can i insert it in my application?

ctrl-c ctrl-v ?

not that.
how can i insert the time syntax to my application syntax?

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.