hello...

i am new student in IT and i have a problem which make me suffer ...

we got exercise to do ... which i have to build a programme that accept the time and acceleration from the user and calculate the velocity ...

my problem now is how to force the user to enter the time as HH:MM:SS
and how can i multiplied with the acceleration to get the velocity ??

we learned until function only .. we didnt get into the complexe thing yet !!
so please help me !!!

Recommended Answers

All 5 Replies

You can get the time by using structures about time but If you are at the begining, I advice you to get the time ordinaly.

for example:

printf("\nEnter hour(s): ");
scanf("%d",&h);
printf("\nEnter min(s): ");
scanf("%d",&m);
printf("\nEnter seconds(s): ");
scanf("%d",&s);

After getting the acceleration; the formula to calculate velocity must be like this:
velocity = StartingSpeed + ((h * 3600 + m * 60 + s) * acceleration) / 2;

Good Luck

well ... to force the input in HH:MM:SS format you can declare a dummy char variable which you will not use anywhere in your program logic but will only use to filter colons from the user's input. Now say you have declare three int variables with names like hours, minutes, seconds to store the values of HH, MM and SS respectively and a char variable of, say, the name c which you will use to filter out colon then prompt the user like this:

cout << "Enter time in this format HH:MM:SS: ";

and in the next line, take the input as:

cin >> hours >> c >> minutes >> c >> seconds;

as you may know that >> operator is evaluated from left to right so if user enters something like:

02:15:30

then cin will automatically assign 2 to "hours", 15 to "minutes", 30 to "seconds" and : to "c".

after that you can convert this time to seconds like this.

int timeInSeconds = seconds;
timeInSeconds = timeInSeconds + (minutes*60);
timeInSeconds = timeInSeconds + (hours*60*60);

and then calculate the velocity using an expression like:

velocity = acceleration * time;

Hope you understand it.

please solve this.


Q1) Write a program that take a number (maximum 5 digit) input from the user and check whether number is palindrome or not. Palindrome is a number which if read from either side gives the same number
1, 66, 121, 1441, 12321 etc are palindrome, while 21, 123, 2345, 23456 are not.

please solve this.


Q1) Write a program that take a number (maximum 5 digit) input from the user and check whether number is palindrome or not. Palindrome is a number which if read from either side gives the same number
1, 66, 121, 1441, 12321 etc are palindrome, while 21, 123, 2345, 23456 are not.

-Ask scanf or cin to get number in while loop till user enter a valid value ( max 5 digits)
-Use itoa() or sprintf to convert your number to string in array which you can easily compare digits.

Little advice; don't get the full code from somebody so you can learn while you are searching for the answers.

edit : I hope this will help you, and you won't be angry to me...

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.