| View previous topic :: View next topic |
| Author |
Message |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Oct 09, 2007 11:03 am Post subject: I'm damn new to C++ |
|
|
Hey guys, I hope you can help me out.
Im decided to start a bit c++. I searched for some tuts on google and found a simple tut (This but its german lol)
Well I checked in the "if and else" section and found this:
| Code: | #include <iostream>
using namespace std;
int main()
{
cout<<"Please enter a number\n";
int a;
cin>>a;
cout<<"Please enter a once more number\n";
int b;
cin>>b;
if(a==b)
{
cout<<"Both numbers are commensurate";
}
if(a<b)
{
cout<<a<<" is smaller then "<<b;
}
if(a>b)
{
cout<<a<<" is bigger then "<<b;
}
cout<<"\n";
} |
Very easy for you guys.. xD
But after I entered two numbers it just closes the application..WHY?
lol, Im just wondering cuz it should tell me something about these two numbers.
Please answer the question newbfriendly
ty everyone! |
|
| Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Tue Oct 09, 2007 11:08 am Post subject: |
|
|
| open your program from the cmd, or add a cin at the end |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Oct 09, 2007 11:15 am Post subject: |
|
|
well lol yea I tried it already with cin.get(); but not everywhere.
| Code: | #include <iostream>
using namespace std;
int main()
{
cout<<"Please enter a number\n";
int a;
cin>>a;
cout<<"Please enter a once more number\n";
int b;
cin>>b;
if(a==b)
{
cout<<"Both numbers are commensurate";
cin.get();
}
if(a<b)
{
cout<<a<<" is smaller then "<<b;
cin.get();
}
if(a>b)
{
cout<<a<<" is bigger then "<<b;
cin.get();
}
cout<<"\n";
cin.get();
} |
Worked ! thx  |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Oct 09, 2007 11:19 am Post subject: |
|
|
ur code shoudnt even compile.... you dont even return EXIT_SUCCESS (0)
revised script:
| Code: | #include <iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Please enter a number\n";
cin>>a;
cout<<"Please enter a once more number\n";
cin>>b;
if(a==b)
{
cout<<"Both numbers are commensurate";
}
else if(a<b)
{
cout<<a<<" is smaller then "<<b;
}
else if(a>b)
{
cout<<a<<" is bigger then "<<b;
}
cout<<"\n";
cin.get();
return 0;
} |
_________________
Last edited by lurc on Tue Oct 09, 2007 11:22 am; edited 2 times in total |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Oct 09, 2007 11:21 am Post subject: |
|
|
| lurc wrote: | ur code shoudnt even compile.... you dont even return EXIT_SUCCESS (0)
revised script:
| Code: | #include <iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Please enter a number\n";
cin>>a;
cout<<"Please enter a once more number\n";
cin>>b;
if(a==b)
{
cout<<"Both numbers are commensurate";
}
else if(a<b)
{
cout<<a<<" is smaller then "<<b;
}
else if(a>b)
{
cout<<a<<" is bigger then "<<b;
}
cout<<"\n";
cin.get();
return 0;
} |
|
This doesnt work for me.
This one I posted works xD.
I guess my Microsoft Visual C++ sux, eh? |
|
| Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Tue Oct 09, 2007 12:12 pm Post subject: |
|
|
| It doesn't make any sence, you must return a value for int functions in VC++, else it won't compile.. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Oct 09, 2007 12:17 pm Post subject: |
|
|
try
| Code: | | return EXIT_SUCCESS; |
or however u spell success
| assaf84 wrote: | | It doesn't make any sence, you must return a value for int functions in VC++, else it won't compile.. |
yea, your right.
unless, for some reason his compiler is changing int main to void main _________________
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Oct 09, 2007 12:24 pm Post subject: |
|
|
| What compiler should I use instead ? |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Oct 09, 2007 12:44 pm Post subject: |
|
|
VC++ is fine. You could try the Intel one if you really want though.
also, int main(void) |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Oct 09, 2007 12:49 pm Post subject: |
|
|
ahhhrg
Only
| Code: | #include <iostream>
using namespace std;
int main()
{
cout<<"Please enter a number\n";
int a;
cin>>a;
cout<<"Please enter a once more number\n";
int b;
cin>>b;
if(a==b)
{
cout<<"Both numbers are commensurate";
cin.get();
}
if(a<b)
{
cout<<a<<" is smaller then "<<b;
cin.get();
}
if(a>b)
{
cout<<a<<" is bigger then "<<b;
cin.get();
}
cout<<"\n";
cin.get();
} |
Is working  |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Oct 09, 2007 1:00 pm Post subject: |
|
|
| well, how is not working? |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Oct 09, 2007 1:03 pm Post subject: |
|
|
| if I use your opion It closes after I entered the 2 numbers. |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Tue Oct 09, 2007 1:09 pm Post subject: |
|
|
That's because you're running it from explorer so you can't see the output. start->run->cmd
| Code: |
cd path\to\executable
yourexecutable.exe
|
and you will be able to see it all |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Oct 09, 2007 1:12 pm Post subject: |
|
|
run it from the command line, like:
cd c:\someplace\someplace\there
program.exe
edit: damnit, beaten to it.  |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Oct 09, 2007 1:20 pm Post subject: |
|
|
| appalsap wrote: | That's because you're running it from explorer so you can't see the output. start->run->cmd
| Code: |
cd path\to\executable
yourexecutable.exe
|
and you will be able to see it all |
Yea it's wroking in that way, thx . But I justed wanted it to work w/o cmd  |
|
| Back to top |
|
 |
|