problem with numerical calculations

This is a discussion on problem with numerical calculations within the C++ Programming forums, part of the General Programming Boards category; im having a similar problem with my program Code: #include <iostream> using namespace std; int Sel; int statup; int startstats; ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    2
    im having a similar problem with my program
    Code:
    #include <iostream>
    using namespace std;
           
           int Sel;
           int statup;
           int startstats; 
           int X,Y,Z;
    struct database {
           
           char username[32];
           char charname[32]; 
           char passwrd [32];
           int str,intel,magic;
           int inventory;
          
           
    };
      int main ()
      {   X = -1;
          cout<<"Welcome to the Velvet Knight character registration form\n";
          database VNcharacters; /*creates a 'table' in  database*/
          startstats = 5;
          VNcharacters.inventory = 256;
          cout<<"enter your username:";
          cin>>VNcharacters.username;
          cin.ignore();
          cout<<"\nUsername:" <<VNcharacters.username<<"\nPlease enter your characters name:";
          cin>>VNcharacters.charname;
          cin.ignore();
          cout<<"\nPlease enter your password:";
          cin>>VNcharacters.passwrd;
          cin.ignore();
          cout<<"\nPlease select the attributes you would likeimprove:"; /*this is where i need help*/
          cout<<"\n * 1) Strength\n\n * 2) Wisdom\n\n * 3) Intelligence";
          cin>>statup;
          switch (Sel) {
                 case 1:
                      VNcharacters.str++ ;
                      startstats = startstats + X;
                 break;
                 }
          cout<<"\nYou have " <<(startstats)<<" points left\n";
          cin.ignore();
          cout<<"\nPress any Key to continue..";
          cin.ignore();
          return 0;
           }
    i want it to reduce the number in startiungstats by one wach time an optino is selected any help would be apppreciated
    Last edited by phyushin; 01-28-2006 at 02:35 PM.

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Can you restate the question?

  3. #3
    xhi
    xhi is offline
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    Code:
    cout<<"\nPlease select the attributes you would likeimprove:"; /*this is where i need help*/
          cout<<"\n * 1) Strength\n\n * 2) Wisdom\n\n * 3) Intelligence";
          cin>>statup;
          switch (Sel) {
                 case 1:
                      VNcharacters.str++ ;
                      startstats = startstats + X;
                 break;
                 }
          cout<<"\nYou have " <<(startstats)<<" points left\n";
          cin.ignore();
          cout<<"\nPress any Key to continue..";
    to simply decrease startstats by one, you can do
    --startstats;
    it appears you want to have the selection routine run until you are out of startstats, right? so you should put it in a loop.. somthing to the effect of..
    Code:
    cout<<"Please select the attributes you would likeimprove:" << endl;
          cout << "1) Strength\n2) Wisdom\n3) Intelligence\n4) Quit" << endl;
          cin>>statup;
    while(Sel > 0 && Sel < 4 && startstats){
          switch (Sel) {
                 case 1:
                      VNcharacters.str++ ;
                      --startstats;
                 break;
                 }
          cout<<"You have " << startstats << " points left" << endl;
          cout<<"Please select the attributes you would likeimprove:" << endl;
          cout << "1) Strength\n2) Wisdom\n3) Intelligence\n4) Quit" << endl;
          cin >> statup;
    }
    somthing like that.. also should not make your vars global.. you could do your loop and test cases in the loop a number of ways but this hopefully helps a little to give an idea..
    Last edited by xhi; 01-28-2006 at 03:48 PM. Reason: wasnt done, damn alt+f-alt+s habit always submits the code

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    2
    i figured it out thanx 4 the help guys, was wondering could you help me with something else
    i want to make a dummy file creatorbut i dont know how to get the program to halt writing to the dummy file when it reaches a certain size would it be a while loop and if it is how would i get the filesize as a variable??

  5. #5
    xhi
    xhi is offline
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    well if you keep track of what you write.. and then test that amount.. then stop when it reaches a certain size... that should do it .. shouldnt it?

    if you would want to track down to the bit.. you should be aware of how the file will be padded if say you end up in the middle of a byte when you need to stop...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Input From a Text File - A Specific Problem.
    By Eddie K in forum C Programming
    Replies: 4
    Last Post: 03-09-2006, 02:50 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  5. array problem?
    By ssjnamek in forum C Programming
    Replies: 14
    Last Post: 02-08-2006, 05:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21