Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

115 Neutral

About SaintForHire

  • Rank
  1. SaintForHire

    Pointers and functions help

    Oh wow that's really cool. So basically I have to make the input equal to "buffer"(or whatever I want to call it). And then tell the stringstream to equal that.   As a side thing, is there any way to make the input equal the stringstream directly or do I always have to go through the extra step to make it equal a string, and then put that into the stringstream?
  2. SaintForHire

    Pointers and functions help

      Admittedly I don't know what a stringstream is. I've searched a little bit after reading your post and tried to use it, but I couldn't find anyway to actually implement it correctly. Help would be appreciated.    I used the code at this link to help me.   I added the #include <sstream> in the header and also changed the getNames function to this void getNames(int size, int *number, string *name) {     stringstream ss;     for (int i = 0; i < size; ++i)     {         cout << "Name " << i + 1 << ": ";         getline(cin, name[i]);         cout << "Number " << i + 1 << ": ";         cin >> number[i];         ss >> number[i];     } }
  3. SaintForHire

    Pointers and functions help

    I haven't been learning c++ but for a few months and I've come to pointers. So far, the most confusing thing I've encountered. I'm using a text book that I borrowed from a friend to learn from and one of the exercises in the book asks me to ask the user to type in a name and a score, separated in to two separate arrays using pointers.    I've pulled the snippet of the code that I've been working on below. The problem is that after the first pass of the function (or even before that if I put an integer into the program before the function even begins) the getline(cin, name) in the function getNames doesn't do anything anymore. My question is why doesn't it work?    Thanks! #include <iostream> #include <string>   using namespace std;   void getNames(int, int *, string *);   int main() {     int x = 2;       int *nums;     string *names;     nums = new int[x];     names = new string[x];       getNames(x, nums, names);       for (int i = 0; i < x; ++i)         cout << names[i] << " " << nums[i] << endl; }   void getNames(int size, int *number, string *name) {     for (int i = 0; i < size; ++i)     {         cout << "Name " << i + 1 << ": ";         getline(cin, name[i]);         cout << "Number " << i + 1 << ": ";         cin >> number[i];     } }
  4. SaintForHire

    2-dimensional array help

    Thx all for the help. It helped immensely.       This made the most sense to me and makes my code A LOT smaller, so I used this as my personal choice fix.   Also thank you Pink. I think my code was confusing me a little bit, so I just started throwing random stuff at it to get it to work, which just confused me more.
  5. I've tried many different variations of the following code. I've even tried using the void function as the hub for the increase function, but I can't seem to figure it out. I feel like I'm really close, but I just don't get it. #include <iostream> #include <iomanip> using namespace std;   const int division = 6; const int quarters = 4;   void list(double [][quarters]); double quarterlyIncrease(double [][quarters]);   int main() {     double arr[division][quarters];       //This is where arr is given values.     for (int i = 0; i < division; ++i)     {         cout << "Please enter the sales figures in division " << i + 1 << " for all four quarters\n";         for (int j = 0; j < quarters; ++j)         {             cout << "Quarter " << j + 1 << ": $";             cin >> arr[i][j];             if (arr[i][j] < 0)             {                 cout << "Please enter a positive sales figure: $";                 cin >> arr[i][j];             }         }         cout << endl;     }       double increases = quarterlyIncrease(arr);     list(arr); }   //This is where the list of all the division's sales during each quarter are outputted. void list(double arr[][quarters]) {     for (int i = 0; i < division; ++i)     {         double total;         double increase = 0.0;         cout << "Division " << i + 1 << " Sales\n";         cout << "------------------------\n";         cout << setprecision(2) << fixed;         for (int j = 0; j < quarters; ++j)         {             cout << "The sales for Quarter " << j + 1 << ": $" << arr[i][j] << endl;             double increases = quarterlyIncrease(arr);             if (j > 0)             {                 cout << "The increase from the previous quarter: $" << increases;                 cout << endl;             }         }         cout << endl;     } }   double quarterlyIncrease(double arr[][quarters]) {     double total = 0.0;     double increase = 0.0;     for (int i = 0; i < division; ++i)     {         for(int j = 0; j < quarters; ++j)         {             increase += arr[i][j];             if (j > 0)             {                 total = arr[i][j];                 increase += total - increase;                 return increase;             }         }     } } I don't know how to make the increase between each quarter work. Basically, when I try to output the increase (no matter how I've tried it) it seems to output either the first number entered into the 2 dimensional array, or the second number entered in as the 2 dimensional array.    The current code shows it as the second number entered (meaning quarter 2 in division 1 is always the increase throughout the entire code).   Thanks for the help!    
  6. SaintForHire

    A little confused with nested for loops

    Oh wow, I get it now. It's hard to explain out loud how I was thinking of it before. It was just weird for me I guess.    Thank both of you very much.
  7. Hello. Kind of new to gamedev.net and to programming in general. Hopefully this is the right place to post.   I finished this code below and got it to work. The first nested for loop outputs + signs on each line. 1 on the first line, all the way to 10 on the 10th line.   The second nested for loop does the same just reverse.   My question is, why doesn't the second nested for loop terminate when j is no longer >= i?  #include <iostream>   using namespace std;   int main() {     for (int i = 1; i <= 10; ++i)     {         for (int j = 1; j <= i; ++j)         {             cout << "+";         }         cout << endl;     }     cout << endl;       for (int i = 1; i <= 10; ++i)     {         for (int j = 10; j >= i; --j)         {             cout << "+";         }         cout << endl;     } }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!