Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include <cs50.h>
#include <stdio.h>

int main(void)
{
    // ask for an integer
    printf("how old are you?\n");
    int n = GetInt();
    
    // analyse users input
    if (n >= 1 && n <= 12)
    {
        printf("you're still a baby\n");
    
    }
    else if (n >= 13 && n <= 19)
    {
        printf("you're a teenager\n");
    }
    else if (n >= 20 && n <= 39)
    {
        printf("adult?\n");
    }
    else if (n >= 40 && n <= 100)
    {
        printf("Damn, you old!\n");
    }
    else if (n > 101)
    {
        printf("How are you not dead?\n");
    }
}


What I have tried:

C++
#include <stdio.h>
#include <cs50.h>
#include <string.h>

int main(void)
{
    // choose a planet
    printf("Choose a planet\n");
    
    if (strncmp = "Mercury")
    {
        printf("Mercury takes 87.9 Earth days to complete its orbit around the Sun");
    }</string.h></cs50.h></stdio.h></stdio.h></cs50.h>
Posted
Updated 7-Mar-16 22:27pm
v2
Comments
OriginalGriff 8-Mar-16 2:15am    
And?
What is your problem here?
All you have done is post up two bits of code, without telling us what problem you are having!
We can't do anything from just that: we only get what you tell us to work with!
Patrice T 8-Mar-16 3:51am    
HomeWork ! What is the problem ?
First bit of code is unrelated to tittle.

1 solution

C++
if (strncmp = "Mercury")

will not even compile, let alone produce a meaningful result. See strncmp, wcsncmp, _mbsncmp, _mbsncmp_l[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900