C++ :: Write Program To Convert Time From 24-hour Notation To 12-hour Notation
Dec 10, 2013
Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the input, and function(s) to display the results. (For 12-hour time notation, your program must display AM or PM.)
It is showing error because may be I was not able to put that if statement inside any function. find out the error sand complete the program with corrected code.
this runs and everything just fine, however i cant seem to figure out why the program isnt telling to user to use a valid time for hours and minutes when it's entered over the standard time limits (i.e. cant go over 23 hours and over 59 minutes)
#include <iostream> using namespace std; //functions for converting 24hr to 12hr notation //parameters use int and void as a data type
I was trying 2 write a program that would calculate the sum notation of 1/(i^2) with the starting number to be 1 and goes up to the nth term. For instance if the user inputed 3 then the sum would look like 1+1/4+1/9. I somehow made a code but it gets weird numbers which some include negative numbers... when I input a number that is above 5.
#include <stdio.h> #include <math.h> int main(int argc, const char * argv[]) { int n; register int i=1; float b;//For part 1
[Code] ....
For some reason I can't edit printf("%f",/>/>; when I post it as the topic so ignore that part cuz Ik its supposed to be written as printf("%f",/>;
I'm writing a program that converts seconds to hours and minutes - That works fine! But if I write: 3700 seconds It answers That equals to: 1 hours, 1 minutes and 40 seconds.
I now want my program to write 1 hour, 1 minute and 40 seconds.
And if there is no hours at all it should only write 400 seconds equals 6 minutes and 40 seconds.
To sum up: The program shall write hour/hours minute/minutes second/seconds correct.
I've made one succesfull program, but it was written with 27 "if-statements" and I know there is a better way.
Code:
#include <stdio.h> int main(void) {
[Code]...
how to make the program know when to write hour or hours?
I want to add a count down timer to my testing software 1hr and 30min
Its a 32bit console application, I want the countdown timer outputted above each question on the right side, timer only needs to output the time left at the top of each question so a live outputted timer is not important.
Questions are not random generated.
Also how to output "out of time" if the timer reaches 0 and for the test to end, I think branching is involved not too sure.
I already have, std::srand( std::time(0) ) ; at the start of the test to randomly generate the answer order.
I have to program something that would convert miles per hour to seconds per mile.
I'm having an issue with something that I coded. Lines 21-23 are not showing up when I compile the program. What I'm trying to do is convert seconds into minutes.
What I have so far is
#include <iostream> using namespace std; int main() { double miles_per_hour, minutes_per_hour, seconds_per_hour, seconds, minutes; cout << "Enter the miles per hour: "; cin >> miles_per_hour;
Is there a simple notation to check if a value is within a plus or minus range?
E.g. //I read a value A. delay(50); //Read value again -calling this value B delay(50); //Read value again -calling this value C delay(50); //Read value again -calling this value D delay(50); //Read value again -calling this value E Check IF first value A is within 5 of the value B and within 5 of value C, etc.
I can think of a few round about ways of doing this but is there any simple "equals to plus or minus" notation? (what I actually want to do is to check a lot more values than this and it will get very complicated with any of my solutions)....
I just wrote code that is a program for a relativity calculator. However many of my outputs (because the values tend to be large) end up in scientific notation. Although useful, its not great for the laymen, or nice looking.
How can I change it so that output is not in scientific notation? here is the code:
// This program/converter is designed to find the desired 'real' values using Einstein's theory of relativity
Ex. 5 4 + 3 10 * + the answer is 39 because if I change it to infix, it's (5 + 4) + (3 * 10)
I need to use vector to compute the value. Here is what I think. First, I save leftmost from the string. If it is a number, I push. If that is a operation, I pop twice and push the result. By doing it until the string is emptied, the vector will only contain the final answer. And here is my code
#include <iostream> #include <vector> #include <string> using namespace std; int main(){ vector<int> stack; string input;
[Code] .....
When I put 1 1 + or 2 2 +, it showing me a correct answer, but when I put the above example which is 5 4 + 3 10 * +, it shows 30 instead of 39.
I'm trying to make an infix to postfix notation calculator. The difficult thing is th stack class is custom. It's not to hard to understand, I don't know if the fact that it is that way will not allow me to receive support. The difference is that the pop functions is as such:
stack<char> conversion; char temp; conversion.pop(temp);//It receives a parameter and puts the popped element in there. conversion.peek(temp);//Places the top element in said parameter
not only that... but these are boolean functions. they return true if the operation was completed. So they can be used as conditions.
#include<iostream> #include<string> #include<stdio.h> #include"stack.h" using namespace std; int main(void) { Stack<char> conversion; string infix,inter,temps;
[Code] .....
The error is that i am mismanaging parenthesis handling and i can't seem to grasp where and how.
An example input is:(35+7)-(9-2) that input gives me:35 7 + 9 2 ) - but another input such as :(35+7)/7 outputs as: 35 7 + 7 /. Totally fine.
double number = 10000000; int range;//the length of the string result string result;//holds the number in a string ostringstream convert; //stream used for the conversion convert << number; result = convert.str();
range = result.length();
I'm trying to convert a double to a string and when the number goes to ten million it goes to scientific notation and it shows it in the string. How do I stop it from do that?
Write a program in C++ that calculates the amount to be paid to an employee based on the hours worked and rate per hour. A user will enter hours worked and rate per hour for an employee. Your program should have a function payCheck that calculates and returns the amount to be paid. The formula for calculating the salary amount is as follows: for the first 40 hours, the rate is the given rate (the rate that a user has entered); for hours over 40, the rate is 1.5 times the given rate.
I had write my own coding, but it keeps error. it is okay. But i still don't think i could share here? Still running... I will update my coding for you alls to check for any syntax or logic error. The problem is i need to calculate if the employee work for more than 40 hours which 1.5 times.
My code compiled well(After long Messing up with my head). But, i still not satisfied of my output as i expected. My code ought to sort the object of person comparing their salary. But, its not.
Code: #include <iostream> #include <string> using namespace std; class person { protected : string name; float salary;
[Code] ....
It doesn't sort the object of class person rather than it prints out the stored value as it is.
I have this code in order to make a RPN calculator,but im trying to read from the console entering the expression in reverse polish notation,Also I think it will be better to use fgets() instead of scanf since the person can entere something like this 3 2 1 + x
I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this
I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.
Would also like to know why the argument call needed &head instead of just head.
remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);