Youbob with a problem

Discussion in 'C++' started by youbob, Feb 1, 2009.

  1. youbob

    youbob New Member

    Joined:
    Feb 1, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hello,
    I'm new to this forum, and hope this is a place that values it's new people. I hope to both learn form tutorials on C++ and to start programming under this Language. My gaol is to produce a very complex text base RPG game. To which these plans on how it suppose to look and feel are still kept secret.
    I already understand a get deal about computers. It's my gaol to expand my knowledge, and go into a new area of the control of the PC.


    Right now I have a bit of a problem on one program that I 'm working on.

    I want to make a Percent solving program.
    There is a simple formula to figure out percent problems
    the part , base, and rate.

    P = B * R
    To find out the percent.
    R = P/B

    To find out the part.
    p = B * R

    to find out the base

    b = p * r * 100 ( sense r is .1)

    so I have a simple 10 out of 100 is 10%

    I made a C++ program to id this formula.
    This is very simple program.
    Code:
    #include <iostream>
    using namespace std; 
    
    int main()
    {
    
    // seting up my var
    float p; 
    float b;
    float r; 
    
    
    cout << "I want to show the percent formula, of base, part, and rate";
    cout <<"form theses number.";
    cout <<" 10 out of 100 is 10 percent\n"; 
    
    // to find the Precent of numbers 10 form 100. 
    p = 10; 
    b = 100; 
    r = (p/b)*100; 
    
      
     
    // my output for the precent
    cout <<"This is the rate:" << r <<"\n";
    
    
    // To find the Part 
    
    b = 100; 
    r = .10; 
    p = r * b; 
    
    // my out put to the part
    
    cout <<"This is the part:" << p << "\n";
    
    
    // To find the base 
    r = .10; 
    p = 10; 
    
    b = p * r * 100; 
    
    
    // my output to base
    cout << "This is the base:" << b << "\n";
    
    
    getchar(); 
    return 0; 
    
    }
    
    
    

    So my problem is How do I make input and output all of this. as in the user could just type in 2 sets of numbers to have an answer form this formula of Rate, base or Part.

    I'll will have a program ready for this but at a later time I want to see if any body here can figure it out first
     
  2. cpulocksmith

    cpulocksmith New Member

    Joined:
    Jul 23, 2008
    Messages:
    289
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    student
    Location:
    canada
    ok well i through this together for yeah. i hope this is what you ment of not then just yell at me. i dont know if it is the lack of sleep on my part but i dont think you explaned your problem very well. so i tried. here yeah go.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(){
    
    double firstNumber=0;
    double secondNumber=0;
    double percentage=0;
    
    
    cout<<"ok you must enter two numbers...(if i understand this kid right lol.) the first being the number out of whatever. like 45 out of 100 for example.\n"<<endl;
    
     cin>>firstNumber;
    
    cout<<"\n ok now enter the second number(the on that the first will be out of)\n"<<endl;
    
    cin>>secondNumber;
    
    percentage = (firstNumber / secondNumber) * 100;
    
    cout<<"so your percentage would be ... "<<percentage<<" %"<<endl;
    } 
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Gaol is another word for jail. Do you mean goal?
     
  4. cpulocksmith

    cpulocksmith New Member

    Joined:
    Jul 23, 2008
    Messages:
    289
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    student
    Location:
    canada
    master xpi0t0s i think it is pretty safe to say he is trying to say goal... lol... or maybe his jail is to expand his knowledge... oh oh oh. or maybe he is trapped like a ghost or somthing and cant pass over till he passes on what he knows about c++!!!... i think i need sleep... and i think i read to much manga...
     
  5. youbob

    youbob New Member

    Joined:
    Feb 1, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Cool but look at the code I just made...

    I must tell you all that this code doesn't do what I want it to do.

    I want to to where the user can find the answer to the percent problem no matter which 2 sets of number he or she starts with. and I want the program to figure this out and give the currant answer.
    Code:
    #include <iostream> 
    using namespace std; 
    
    int main()
    {
    // my variables
    
    int base=0; 
    int part=0; 
    int rate=0; 
    
    // my instruction
    
    cout << "In oder to solve your percent problem you must enter in two ";
    cout << "number values\n ";
    cout << "Press Enter to continue";
    getchar(); 
    
    // my set up
    
    cout <<"Enter in the part number(such as the of statement)\n ";
    cin >> part;
    cout << "Enter in the base numeber( such as what the percent epuals to\n ";
    cin >> base; 
    cout <<"Enther in the rate number (such as the percent)\n ";
    cin >> rate; 
    
    // my options and functions 
    
    if (part=0){
    part = base * rate;
    cout << "Your ansewer is"<< part << endl;
    getchar();
    }
    if (base=0){
    base = part * rate * 100;
    cout <<"Your ansewer is"<< base << endl;
    getchar();
    }
    
    if (rate=0){
    rate = base / part; 
    cout << "Your ansewer is "<< rate << endl;
    getchar();
    }
    
    
    return 0; 
    
    
    }
    
    
    
    
    any idea I know I'm close
     
  6. cpulocksmith

    cpulocksmith New Member

    Joined:
    Jul 23, 2008
    Messages:
    289
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    student
    Location:
    canada
    do you mean you want the player to enter all three numbers but enter 0 for one. the one that gets the 0 will be solved by the program?
     
  7. cpulocksmith

    cpulocksmith New Member

    Joined:
    Jul 23, 2008
    Messages:
    289
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    student
    Location:
    canada
    alright, how about trying this, i think it is what you want.

    Code:
    #include <iostream> 
    using namespace std; 
    
    int main()
    {
    // my variables
    
    double base=0; 
    double part=0; 
    double rate=0; 
    
    // my instruction
    
    cout << "In oder to solve your percent problem you must enter in two ";
    cout << "number values\n ";
    cout << "Press Enter to continue";
    getchar(); 
    
    // my set up
    
    cout <<"Enter in the part number(such as the of statement)\n ";
    cin >> part;
    cout << "Enter in the base numeber( such as what the percent epuals to\n ";
    cin >> base; 
    cout <<"Enther in the rate number (such as the percent)\n ";
    cin >> rate; 
    
    // my options and functions 
    
    if (part==0){
    part = base * rate;
    cout << "Your ansewer is"<< part << endl;
    getchar();
    }else if (base==0){
    base = part * rate * 100;
    cout <<"Your ansewer is"<< base << endl;
    getchar();
    }else if (rate==0){
    rate = base / part; 
    cout << "Your ansewer is "<< rate << endl;
    getchar();
    }
    
    
    return 0; 
    
    
    }
    your variable types were wrong you are dealing with percent so a decimal, you had them as int witch cannot do into a decimal. double is a decimal type. also for your if statment you put

    Code:
    if (part=0){
    when you should have 2 equal signs in there. like...

    Code:
    if (part==0){
    also i changed your ifs to else ifs. and i also changed

    Code:
    if (base==0){
    base = part * rate * 100;
    cout <<"Your ansewer is"<< base << endl;
    getchar();
    there are two things wrong with the above. 1) you would need to put "(part * rate) * 100" to times the sum of part and rate by 100.
    2) you dont need to times anything by 100. i think that was just a slip up, you got it right in the "if (part == 0)" so i think it is just a oops.

    so i think that should be that. hope that helped.
     
    Last edited: Feb 2, 2009
  8. youbob

    youbob New Member

    Joined:
    Feb 1, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    THANk you Ya the first part was a slip up But thank you... Now I have to make it into something even more complex.
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Heh, I like the "master" bit, especially having just watched Kung Fu Panda again. Maybe I should change my nick to Oogway... :)
     
  10. youbob

    youbob New Member

    Joined:
    Feb 1, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    funny
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice