You are writing a c++ program, don't the input string to char* -- just use std::string's == operator (and don't use the variable name "string" because it is the name of a c++ class and will confuse the compiler. I don't know the relevance of i, but that is probably something else in your program.
std::string input_string.
getline(cin,input_string);
if(i == 25 && input_string == "string")
{
// do something
}
else
if(i == 12 && input_string == "strings")
{
// do something else
}
>>but it manages to fufil the first if-condition but couldn't fufil the second if-condition.
what are the values of i and input_string? put a print statement somewhere or learn to use your compiler's debugger. Also: note the spelling of "string" and "strings" are not the same in your post. Is that true in your actual program? If it is, maybe that is the reason it never falls into the second condition.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
remove the else condition.
if((i==25)&&(input_string=="ca"))
input_string="ba";
//else
if((i==25)&&(input_string=="ba"))
ampm="ca";
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
You should put
equihrs=equihrs-12;
inside this if also
if(equihrs==12)
Other than that I dont see any problems
dilip.mathews
Junior Poster in Training
89 posts since Jun 2006
Reputation Points: 16
Solved Threads: 3
Have you checked your prog. The program is switching between am and pm.
I gave the input as 5 30 am and time difference 9. The o/p I got is 2:30pm. This is infact correct. Then why you are saying its not switching???
The problem I am seeing with your code is
Suppose I gave the input time as 0 0 am and time difference as 12.
The o/p should be 0:00pm but your program o/ps 12:00pm . This is infact wrong. Thats why I suggested to put
equihrs=equihrs-12;
inside
if(equihrs==12)
dilip.mathews
Junior Poster in Training
89 posts since Jun 2006
Reputation Points: 16
Solved Threads: 3
if(equihrs<12)
{
}
else
{
if(equihrs==12)
{
void ampmcalculation();
}
else
{
{
void ampmcalculation(string ampm);
equihrs=equihrs-12;
}
The line inRED above is not calling a function, it is just declaring the function. If you want it to actually call that function you have to remove the "void" in front of the function name, add a parameter to the function call in the first red line, and the word "string" from the parameter list.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343