hello, i started learning c++, and i made a hello world but how do i need to save this and made this program work?? (i know bit of noobish)
hello, i started learning c++, and i made a hello world but how do i need to save this and made this program work?? (i know bit of noobish)
Plz don't doublepost.Originally Posted by graker
Answer him here:
http://cheatersutopia.com/smforum/in...17648#msg17648
/closed
/reopened on request...
i have done this, i open it then there stand enter price: (fill in) then enter then enter quantity: (fill in again) then i push enter but the screen dissapears but the total price must appear :S how can i fix this?Code:// stringstreams #include <iostream> #include <string> #include <sstream> using namespace std; int main () { string mystr; float price=0; int quantity=0; cout << "Enter price: "; getline (cin,mystr); stringstream(mystr) >> price; cout << "Enter quantity: "; getline (cin,mystr); stringstream(mystr) >> quantity; cout << "Total price: " << price*quantity << endl; return 0; }
and btw
if i start this only a black screen appears for less than a second how can i fix this?Code:// my first c++ program #include <iostream> using namespace std; int main () { cout << "Hello World!" ; cout << "what the fuck!" ; return 0; }
already thx for helping me![]()
Try placing that before your' ending curly brace ( } ).Code:system("PAUSE");
for the second part, the end should be
cin.get ();
}
or something like that
Same as system pause, both require user keypress to end the program. But you can use that i guess.
This may even be better done without stringstreams and getline. Here let me show you.
Code:#include <iostream> void main(void) { float fPrice=0; int nQuantity=0; cout << "Enter price: "; cin >> fPrice; cout << "\nEnter quantity: "; cin >> nQuantity; cout << "\nTotal price: " << fPrice*nQuantity << "\n"; system("PAUSE"); }
Bookmarks