Help with making this variable?

Pages: 12
Hey guys, im just trying to do a simple variable in netbeans for c++... I only started on Hello World like an hour ago. This is what I'm trying to do:


#include <iostream>

using namespace std;

int main() {
int itemsOnHand= 5;
double itemPrice =3.50;
double total;

total = itemsOnHand * itemPrice;

cout << "The Total is: " << total;


return 0;
}


http://i.imgur.com/psTF7.jpg

I've entered everything, and have ran the program. It runs successfully, but the answer comes out as blank. Does anyone know why? There are no errors, but the answer is blank. If there is anyway to fix this, let me know!


Thank you!
Hello Begotten,

There's obviously nothing wrong with the code I had it run myself. Did the console give any output with your "Hello World!" program?
Thank you for Replying so quickly! Hello World worked the first time I did it, so I assumed there was something wrong with my code, but it's showing the same result now.

http://i.imgur.com/hnxVA.jpg
Hmm, this is just a hunch, but I'm willing to bet that a black box pops up, flashes, then closes.
Try putting system("pause"); on the line above return 0;
To support this command you also need to include stdlib.h
Try...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream> 
#include <stdlib.h>

using namespace std; 

int main() { 
int itemsOnHand= 5; 
double itemPrice =3.50; 
double total; 

total = itemsOnHand * itemPrice; 

cout << "The Total is: " << total; 

system("pause");
return 0; 
} 
that box definitely pops up! I assumed that happens every time, I'm stupid.

I did it with system("pause") and #include <stdlib.h>; and I have the same result.

I'm wondering, I had to uninstall and reinstall cygwin once, is that why? I've tried restarting netbeans but that doesn't work at all.
Last edited on
Are you using linux?
Try:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream> 
#include <conio.h>

using namespace std; 

int main() { 
int itemsOnHand= 5; 
double itemPrice =3.50; 
double total; 

total = itemsOnHand * itemPrice; 

cout << "The Total is: " << total; 

getch();
return 0; 
} 
no, im on windows 7 64, I don't know much about linux other than that CS majors love it. I'm only starting college as a freshman in Computer Science in November, and I don't want to waste this summer. Can you tell me more about linux?

I have the same results with your code too.

http://i.imgur.com/GwiLm.jpg

I'm thinking about uninstalling netbeans and reinstalling but that seems like it will take forever.
Hmm, that's strange...
What do the red ! beside the two new lines say?
cannot find include file <conio.h>

Unresolved directive #include <conio.h>
Analyzed system include paths:
C:\cygwin\usr\lib\gcc\i686-pc-cygwin\3.4.4\include\c++
C:\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include\c++
C:\cygwin\usr\lib\gcc\i686-pc-cygwin\3.4.4\include\c++\i686-pc-cygwin
C:\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include\c++\i686-pc-cygwin
C:\cygwin\usr\lib\gcc\i686-pc-cygwin\3.4.4\include\c++\backward
C:\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include\c++\backward
C:\cygwin\usr\lib\gcc\i686-pc-cygwin\3.4.4\include
C:\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include
C:\cygwin\usr\include
C:\cygwin\usr\include\w32api
C:\cygwin\include\w32api

Ctrl+Alt+Click to open include hierarchy




and, unable to solve identified getch
Oh dear...
Did it do the same thing for stdlib.h ?
yea, no exclamation points though. Just blank.
Hmm, try this one again and make sure you recompile?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream> 
#include <stdlib.h>

using namespace std; 

int main() { 
int itemsOnHand= 5; 
double itemPrice =3.50; 
double total; 

total = itemsOnHand * itemPrice; 

cout << "The Total is: " << total; 

system("pause");
return 0; 
}
hmm, this one actually failed. This is what I got when I ran it again:

"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/Wazit/Documents/NetBeansProjects/Beginner'
"/usr/bin/make" -f nbproject/Makefile-Release.mk dist/Release/Cygwin-Windows/beginner.exe
make[2]: Entering directory `/cygdrive/c/Users/Wazit/Documents/NetBeansProjects/Beginner'
mkdir -p dist/Release/Cygwin-Windows
g++ -o dist/Release/Cygwin-Windows/beginner build/Release/Cygwin-Windows/main.o build/Release/Cygwin-Windows/newfile2.o
nbproject/Makefile-Release.mk:62: recipe for target `dist/Release/Cygwin-Windows/beginner.exe' failed
make[2]: Leaving directory `/cygdrive/c/Users/Wazit/Documents/NetBeansProjects/Beginner'
build/Release/Cygwin-Windows/newfile2.o:newfile2.cpp:(.text+0x0): multiple definition of `_main'
nbproject/Makefile-Release.mk:59: recipe for target `.build-conf' failed
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x0): first defined here
make[1]: Leaving directory `/cygdrive/c/Users/Wazit/Documents/NetBeansProjects/Beginner'
collect2: ld returned 1 exit status
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
make[2]: *** [dist/Release/Cygwin-Windows/beginner.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 717ms)
Ok, that one left my head spinning.
My only suggestion to that would be to try the classic Windows troubleshooting: Restart your pc. I know sometimes my compiler starts acting weird, and a quick restart fixes it. If it still doesn't work, then I'm clueless... :/
Last edited on
ill try that now, but, can you tell me more about linux?
I actually know very little about linux. I was just asking because I do not know if the library's I was referencing would work on linux. Google is an excellent resource though ;)
oh. Well, the restart failed.
Hmm, try recompiling your original code?
If that works, I may have included the wrong library or messed up the cpy/pst.
If it doesn't work, then your compiler is probably messed up. I am not familiar with Netbeans, so I can not help you troubleshoot that.
haha, nope. http://i.imgur.com/8pfB1.jpg

im going to have to uninstall and reinstall I guess
That code compiled without errors? It just didn't display.
Pages: 12