Jump to content

I Need Some Help!


CWSGuy406

Recommended Posts

The type double is used for numbers with decimals while the type string is for words. You probably know this but just in case you didn't notice you had stockname set as a double. I use the setw() function to space out my output. It's alot easier than typing a bunch of spaces. Just make sure you include iomanip first. The rest of this is pretty basic, you change the value NUMSTOCKS if you want your program to have more stocks.

 

 

Have you guys done loops yet? This program is alot easier if you use them. You won't have to type the same lines over and over again. The amount gain/lost is a simple multiplication and you can just put that in a new column on the table. I'm a CS major so I love doing this stuff. :headbang If there are any CS haters out there, just think about the people that make places like Soxtalk possible the next time you visit.

 

 

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int NUMSTOCKS = 2;

int main()
{
       string username;
       string date;
       string stocknames[NUMSTOCKS];
       double stockopens[NUMSTOCKS];
       double stockcloses[NUMSTOCKS];
       double stockshares[NUMSTOCKS];


       cout<<"What is your name?"<<endl;
       cin>>username;
       cout<<"What is today's date?"<<endl;
       cin>>date;
       
       for(int i=0; i<NUMSTOCKS; i++)
       {
               cout << "Stock " << i+1 << " : Name?"<<endl;
               cin >> stocknames[i];
               cout << "Stock " << i+1 << " : Opening Value?"<<endl;
               cin >> stockopens[i];
               cout << "Stock " << i+1 << " : Closing Value?"<<endl;
               cin >> stockcloses[i];
               cout << "Stock " << i+1 << " : # of Shares?"<<endl;
               cin >> stockshares[i];
       }
       cout << "Name"<< setw(18) << "Open Price"<< " "
               << "Closing Price"<< " "<< "# of Shares"<<endl;

       for(int i=0; i < NUMSTOCKS; i++)
       {
               cout << stocknames[i]<< setw(18-stocknames[i].length()) << stockopens[i] << setw(11)
                       << stockcloses[i] << setw(13) << stockshares[i] <<endl;
       }

       return 0;
}

Link to comment
Share on other sites

The type double is used for numbers with decimals while the type string is for words.  You probably know this but just in case you didn't notice you had stockname set as a double.  I use the setw() function to space out my output.  It's alot easier than typing a bunch of spaces.  Just make sure you include iomanip first.  The rest of this is pretty basic, you change the value NUMSTOCKS if you want your program to have more stocks.

 

 

Have you guys done loops yet? This program is alot easier if you use them.  You won't have to type the same lines over and over again.  The amount gain/lost is a simple multiplication and you can just put that in a new column on the table.  I'm a CS major so I love doing this stuff.  :headbang If there are any CS haters out there, just think about the people that make places like Soxtalk possible the next time you visit.

 

 

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int NUMSTOCKS = 2;

int main()
{
       string username;
       string date;
       string stocknames[NUMSTOCKS];
       double stockopens[NUMSTOCKS];
       double stockcloses[NUMSTOCKS];
       double stockshares[NUMSTOCKS];


       cout<<"What is your name?"<<endl;
       cin>>username;
       cout<<"What is today's date?"<<endl;
       cin>>date;
       
       for(int i=0; i<NUMSTOCKS; i++)
       {
               cout << "Stock " << i+1 << " : Name?"<<endl;
               cin >> stocknames[i];
               cout << "Stock " << i+1 << " : Opening Value?"<<endl;
               cin >> stockopens[i];
               cout << "Stock " << i+1 << " : Closing Value?"<<endl;
               cin >> stockcloses[i];
               cout << "Stock " << i+1 << " : # of Shares?"<<endl;
               cin >> stockshares[i];
       }
       cout << "Name"<< setw(18) << "Open Price"<< " "
               << "Closing Price"<< " "<< "# of Shares"<<endl;

       for(int i=0; i < NUMSTOCKS; i++)
       {
               cout << stocknames[i]<< setw(18-stocknames[i].length()) << stockopens[i] << setw(11)
                       << stockcloses[i] << setw(13) << stockshares[i] <<endl;
       }

       return 0;
}

i know loops, but from what i could tell CWSGuy wouldn't know what the hell i was talking about.

Thought i'd give ihm the beginner version first.

Link to comment
Share on other sites

Here's a barebones program, the table won't work because i can't remember how to space correctly....and you might need to make some changes to the variable types (don't know if string will work w/ your compiler) but this should give yo uan idea.

 

 

String username;

String date;

Double Stock1name;

Double Stock1open;

Double Stock1close;

Double Stock1shares;

Double Stock2name;

Double Stock2open;

Double Stock2close;

Double Stock2shares;

Double Stock3name;

Double Stock3open;

Double Stock3close;

Double Stock3shares;

 

int main()

{

cout

cin>>username;

cout

cin>>date;

cout

cin>>stock1name;

cout

cin>>stock1open;

cout

cin>>stock1close;

cout

cin>>stock1shares;

cout

cin>>stock2name;

cout

cin>>stock2open;

cout

cin>>stock2close;

cout

cin>>stock2shares;

cout

cin>>stock3name;

cout

cin>>stock3open;

cout

cin>>stock3close;

cout

cin>>stock3shares;

 

cout

cout

cout

cout

 

return 0;

}

I did that type of s*** last year, when I did a college I.T course in my last year of high school. We used VB.NET though.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...