PCaseiro
Power Member
Boas, andava aqui a explorar um bocadinho de C, através de uns tutoriais da Internet do site:
http://www.cprogramming.com
Até que me deparei com uma dúvida. Ia na segunda lição em que tinha que usar condições (if, else e else if).
Experimentei o código fornecido no site (não se se lhe deva chamar código, alguém explica? ) que era o seguinte:
#include <stdio.h>
int main() /* Most important part of the program!
*/
{
int age; /* Need a variable... */
printf( "Please enter your age" ); /* Asks for age */
scanf( "%d", &age ); /* The input is put in age */
if ( age < 100 ) { /* If the age is less than 100 */
printf ("You are pretty young!\n" ); /* Just to show you it works... */
}
else if ( age == 100 ) { /* I use else just to show an example */
printf( "You are old\n" );
}
else {
printf( "You are really old\n" ); /* Executed if no other statement is
*/
}
return 0;
}
e funcionou tudo ás mil maravilhas até que coloquei o meu que está bastante idêntico mas tentei fazer sozinho sem ver para poder praticar mas dá-me um erro que não consigo resolver:
#include <stdio.h>
int main()
{
int age;
printf( "Inserir a idade aqui: " );
scanf ( "%d", &age);
if (age < 100){
printf ( "És bonito");
}
else if ( age == 100);{
printf ("Estás velho!");
}
else {
printf ("Estás mesmo muito velho!");
}
return 0;
}
Line: 13 error: 'else' without a previous 'if'
O estranho é que no dado pelo site aparece else sem um if antes e no meu não aceita...
Agradecia resposta.
Cumps.
http://www.cprogramming.com
Até que me deparei com uma dúvida. Ia na segunda lição em que tinha que usar condições (if, else e else if).
Experimentei o código fornecido no site (não se se lhe deva chamar código, alguém explica? ) que era o seguinte:
#include <stdio.h>
int main() /* Most important part of the program!
*/
{
int age; /* Need a variable... */
printf( "Please enter your age" ); /* Asks for age */
scanf( "%d", &age ); /* The input is put in age */
if ( age < 100 ) { /* If the age is less than 100 */
printf ("You are pretty young!\n" ); /* Just to show you it works... */
}
else if ( age == 100 ) { /* I use else just to show an example */
printf( "You are old\n" );
}
else {
printf( "You are really old\n" ); /* Executed if no other statement is
*/
}
return 0;
}
e funcionou tudo ás mil maravilhas até que coloquei o meu que está bastante idêntico mas tentei fazer sozinho sem ver para poder praticar mas dá-me um erro que não consigo resolver:
#include <stdio.h>
int main()
{
int age;
printf( "Inserir a idade aqui: " );
scanf ( "%d", &age);
if (age < 100){
printf ( "És bonito");
}
else if ( age == 100);{
printf ("Estás velho!");
}
else {
printf ("Estás mesmo muito velho!");
}
return 0;
}
Line: 13 error: 'else' without a previous 'if'
O estranho é que no dado pelo site aparece else sem um if antes e no meu não aceita...
Agradecia resposta.
Cumps.