EvilZone

Programming and Scripting => C - C++ => Topic started by: 6NavI on May 05, 2013, 03:53:13 PM

Title: I can't run codes with strings
Post by: 6NavI on May 05, 2013, 03:53:13 PM
Hey EZ
every time i try to run a codes with strings in them i get the notification that the program has stopped working can some pliz help me to rectify this am using CODEBLOCKS
Even this code won't run am not saying am the one who wrote it but am just using it as an example

Code: [Select]
// 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;
}

Title: Re: I can't run codes with strings
Post by: vezzy on May 05, 2013, 06:50:57 PM
Although the code is sloppy and lacks indentation, I successfully compiled it with g++ and it functions as it should on my end. Scratch the IDE and try it yourself?
Title: Re: I can't run codes with strings
Post by: Chef on June 22, 2013, 08:26:34 PM
Although the code is sloppy and lacks indentation, I successfully compiled it with g++ and it functions as it should on my end. Scratch the IDE and try it yourself?

Explain indentation to me? So far my codes are looking nice and easy to read but I don't wanna end up sloppy!
Title: Re: I can't run codes with strings
Post by: Fur on June 22, 2013, 08:57:07 PM
Explain indentation to me? So far my codes are looking nice and easy to read but I don't wanna end up sloppy!
Indent Style (https://en.wikipedia.org/wiki/Indent_style)

You may want to check out this (http://sydney.edu.au/engineering/it/~scilect/tpop/handouts/Style.htm) for more on style.

Just remember that everyone has their own preferences.