#include <iostream.h> int main() //Most important part of the program! {
int age; //Need a variable... cout<<"Please input your age: "; //Asks for age cin>>age; //The input is put in age if(age<20) //If the age is less than 100 { cout<<"You are pretty young!"; //Just to show it works
} else if(age==100) //I use else just to show an example { cout<<"You are old"; //Just to show you it works... } else { cout<<"You are really old"; //Executed if no other statement is executed }
return 0; }
her har jeg to spørsmål: - Jeg vil sette TO kriterier for en setning...altså en ny if; hvis den er over 20 og mindre enn 50... - Vinduet bare forsvinner når jeg skriver alderen min:(
#include <iostream.h> int main() //Most important part of the program! {
int age; //Need a variable... cout<<"Please input your age: "; //Asks for age cin>>age; //The input is put in age if(age<20) //If the age is less than 100 { cout<<"You are pretty young!"; //Just to show it works
} else if(age==100) //I use else just to show an example { cout<<"You are old"; //Just to show you it works... } else { cout<<"You are really old"; //Executed if no other statement is executed }
cout << "Press ENTER to continue..." << endl; getchar (); return 0; }
Det der er er galt i din koder er at du mangler en header, prøv sådan her:
#include <iostream.h> #include <stdio.h> #include <stdlib.h> int main() //Most important part of the program! {
int age; //Need a variable... cout<<"Please input your age: "; //Asks for age cin>>age; //The input is put in age if(age<20) //If the age is less than 100 { cout<<"You are pretty young!"; //Just to show it works
} else if(age==100) //I use else just to show an example { cout<<"You are old"; //Just to show you it works... } else { cout<<"You are really old"; //Executed if no other statement is executed }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.