|
|
#1 (permalink) Top |
|
Big Geek
![]() |
The following is a very simple c++ program, that i believe should show the value of a variable x. since x = 1/3, i believe that the out put should be 0.3333, however, the output i get is x=0.
can anybody tell me why? Code:
#include <iostream>
using namespace std;
int main()
{
double x=10, dummy;
x = (1/3);
cout << "X : " << x << endl;
cout << "Exit" << endl;
cin >> dummy;
return 0;
}
|
|
|
|
|
#2 (permalink) Top |
|
The King
![]() ![]() Join Date: Jan 2004
Age: 18 Male
Posts: 5,255
Times Helpful: 403
My Mood: Drunk
Status: Offline
|
If you do
Code:
x = 1/3; Code:
x = (1/3.0); Code:
x = (1.0/3);
__________________
Never trust a program you don't have the source code for. ![]() My website | Powerful Desktop Linux | Linux for human beings | Linux for power users | Linux for ricers |
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| major help needed with probaly a simple problem | donkey42 | Linux and Other OSes | 4 | 28-09-2006 01:17 PM |
| Fast, Simple, And Tasty | Kyle89 | Munchie Bar | 3 | 11-08-2006 12:44 AM |
| Simple Question | revler | Power Supplies and UPS's | 5 | 13-04-2006 05:11 PM |
| Simple question | Temporal | Overclocking & Cooling | 8 | 12-02-2004 06:39 PM |
| simple networking | rixx | Networking and Computer Security | 14 | 05-03-2003 10:01 PM |