C++ Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GuidoHunter
    is against custom titles
    • Oct 2003
    • 7371

    #16
    I'm somewhat certain that you can't read in several variables in one line, but if you can, Soccr's corrected line is the way to read the input. Otherwise, just have three different lines.

    Also, you can directly read in an int, double, char, string, or what have you. chickendude had a pretty good code, but I'd make some modifications to it.

    By the way, every program where I had to do it, I went through hell trying to get the program to correctly output decimal values like I wanted (like showing prices with all the necessary trailing zeroes), so if my code for it looks complicated, it is, but it works.

    Assuming all the math is correct, this should read everything in properly and output everything you need with correct precision.

    Code:
    #include <iostream> 
    #include <iomanip>
    
    using namespace std;
    
    void main&#40;&#41; 
    &#123; 
     double oprice, taxrate, markup, fprice, sprice, tax; 
     
     cout.setf&#40;ios&#58;&#58;floatfield | ios&#58;&#58;showpoint&#41;;
     cout<<setprecision&#40;2&#41;;
    
     cout<<"Input the original price, tax rate percentage, and markup percentage"; 
     cin>>oprice;
     cin>>taxrate;
     cin>>markup; 
    
     sprice = oprice * &#40;1 + &#40;markup/100&#41; &#41;; 
     taxprice = sprice * &#40;1 + taxrate/100&#41;; 
     fprice = sprice + taxprice; 
    
     cout<<"Original price is $"<<oprice<<endl; 
     cout<<"Markup is $"<<markup<<endl; 
     cout<<"Taxrate is $"<<taxrate<<endl; 
     cout<<"Store price is $"<<sprice<<endl; 
     cout<<"Sales tax is $"<<tax<<endl; 
     cout<<"Final price is $"<<fprice<<endl; 
    &#125;
    --Guido


    Originally posted by Grandiagod
    Originally posted by Grandiagod
    She has an asshole, in other pics you can see a diaper taped to her dead twin's back.
    Sentences I thought I never would have to type.

    Comment

    • chickendude
      Away from Computer
      FFR Simfile Author
      • Sep 2003
      • 1901

      #17
      RE: C++ Help

      Ok, I looked it up, you were right
      see soccr, you are always right <_<

      Comment

      • dancingmaniac3
        FFR Player
        • Nov 2003
        • 1873

        #18
        RE: C++ Help

        man, i feel so behind because i'm taking a Java/VBNet course.

        Comment

        • JurseyRider734
          lil j the bad b-word
          • Aug 2003
          • 7506

          #19
          Originally posted by GuidoHunter
          I'm somewhat certain that you can't read in several variables in one line, but if you can, Soccr's corrected line is the way to read the input. Otherwise, just have three different lines.

          Also, you can directly read in an int, double, char, string, or what have you. chickendude had a pretty good code, but I'd make some modifications to it.

          By the way, every program where I had to do it, I went through hell trying to get the program to correctly output decimal values like I wanted (like showing prices with all the necessary trailing zeroes), so if my code for it looks complicated, it is, but it works.

          Assuming all the math is correct, this should read everything in properly and output everything you need with correct precision.

          Code:
          #include <iostream> 
          #include <iomanip> &#40;not taught this yet&#41;
          
          using namespace std;
          
          void main&#40;&#41; 
          &#123; 
           double oprice, taxrate, markup, fprice, sprice, tax; 
           
           cout.setf&#40;ios&#58;&#58;floatfield | ios&#58;&#58;showpoint&#41;;
           cout<<setprecision&#40;2&#41;;  &#40;I have no idea what this stuff is, it wasn't taught, so i'm guessing we can't use it&#41;
          
           cout<<"Input the original price, tax rate percentage, and markup percentage";  &#40;these have to be on different lines&#41;
           cin>>oprice;
           cin>>taxrate;
           cin>>markup; 
          
           sprice = oprice * &#40;1 + &#40;markup/100&#41; &#41;; 
           taxprice = sprice * &#40;1 + taxrate/100&#41;; 
           fprice = sprice + taxprice; 
          
           cout<<"Original price is $"<<oprice<<endl; 
           cout<<"Markup is $"<<markup<<endl; 
           cout<<"Taxrate is $"<<taxrate<<endl; 
           cout<<"Store price is $"<<sprice<<endl; 
           cout<<"Sales tax is $"<<tax<<endl; 
           cout<<"Final price is $"<<fprice<<endl; 
          &#125;
          --Guido

          http://andy.mikee385.com

          This is somewhat along the lines of it, but the thing is he isn't asking for the Original price, he isn't asking for the markup, he's not asking for the tax rate. He's only asking for the New Price. That is, after markup and taxes.

          Here's some formulas I had wrote out on paper in class today:
          sellingPrice=originalPrice+addPrice
          addPrice=originalPrice*markupPrice
          newPrice=?

          Like I said, i've only been doing this for a week.

          Well here's kind of what it had looked like

          "Enter the original price of the item: *random number*

          Enter the mark-up percentage: *random number/decimal*

          Enter the tax-rate: *random number/decimal*"


          There has to be formulas that will calculate the newPrice after it's marked up and taxes are applied.

          Such as

          oP = 5
          markup= .5 (50%)
          taxrate= .18 (18% i guess)

          After I figured this out, I got completely lost of what I had to enter the rest of the way...

          It started out like

          int originalPrice
          cout<<"Enter the original price of the item. ";
          cin>>price;
          cout<<endl;
          double markupPrice
          cout<<Enter the markup price. ";


          and so on...

          Hope I clarified some things >_> But Guido's looked somewhat close.
          Originally posted by Arch0wl
          I'd better be considering I own roughly six textbooks on logic and have taken courses involving its extensive use

          Originally posted by Afrobean
          Originally Posted by JurseyRider734
          the fact that you're resorting to threatening physical violence says a lot anyway.
          Just that you're a piece of shit who can't see reason and instead deserves a fucking beating.

          Comment

          • chickendude
            Away from Computer
            FFR Simfile Author
            • Sep 2003
            • 1901

            #20
            The 'Final Price' (using the variable fprice)
            is the new price

            I assumed you put in percentages for salestax and markup

            like 5% sales tax and 20% markup

            tax = storeprice * (1 + (taxrate/100) )
            it just makes the % into a fraction and add one so it increases (so its x1.05 not x.05)

            then
            storeprice = originalprice * (1 + (markup/100) )
            same reasoning

            and new price = storeprice + tax

            thats what I did in my program, and guido made syntax updates

            Comment

            • QreepyBORIS
              FFR Player
              • Feb 2003
              • 7454

              #21
              Soccr's console idea was right. You can do it Nipunn's way without getting any errors or warnings, but you would probably get some sort of logic error. I tried it in one of my programs, it built fine, but it didn't work. I don't remember if there was another problem or if that was it, though.

              In any case, it's just better to use the << or the >> operators with the console instead of commas. For now, at least.

              postcount++;

              Signature subject to change.

              THE ZERRRRRG.

              Comment

              • ad0gg
                FFR Player
                • Dec 2003
                • 989

                #22
                Re: RE: Re: C++ Help

                Originally posted by soccr743
                Qreepy, you read from the console into the buffer which is in char* format... Then, you would need to convert that to a float in order to use it in calculations.
                The function to convert a char * to a float is atof, with its only argument a char * and it returns a value of type float. It is found in in the stdlib.h header file. So you would use it like this:
                Code:
                #include <iostream>
                #include <stdlib>
                using namespace std;
                
                int main&#40;&#41;
                &#123;
                        char asdfString&#91;5&#93; = "54.2";
                        float asdfFloat;
                
                        asdfFloat = atof&#40;asdfString&#41;;
                
                        return 0;
                &#125;
                ...and Voila, you can then use asdfFloat in calculations. The atoi function is exactly the same as the atof function, but it returns an integer value instead.

                Comment

                • User6773

                  #23
                  Re: RE: Re: C++ Help

                  Originally posted by JurseyRider734
                  The only reason i'm posting is because i'm a day behind in my class. So while everyone is on addictinggames, i'm sitting there confused with this goddamn thing.
                  Junior year of high school. In my C++ class, we would go to addictinggames and follow links when we were done with our programming project.

                  I clicked a link called "Flash Flash Revolution" once, on a whim...

                  ...and here I am.

                  Comment

                  • talisman
                    Resident Penguin
                    FFR Simfile Author
                    • May 2003
                    • 4598

                    #24
                    RE: Re: RE: Re: C++ Help

                    jurs' guido's right on... it just tells you more than you want to know.

                    Comment

                    • GuidoHunter
                      is against custom titles
                      • Oct 2003
                      • 7371

                      #25
                      RE: Re: RE: Re: C++ Help

                      Basically, what I wrote is everything you need besides the proper equations. So, if you cut out everything past the precision setting and put in what really needs to be there (I just left chicken's math alone), you'll have a program that does what you want.

                      --Guido


                      Originally posted by Grandiagod
                      Originally posted by Grandiagod
                      She has an asshole, in other pics you can see a diaper taped to her dead twin's back.
                      Sentences I thought I never would have to type.

                      Comment

                      • FFR Player
                        • May 2002
                        • 1088

                        #26
                        RE: Re: RE: Re: C++ Help

                        I entered that, and it wasn't right/there was some kind of error/it's not coded like my other projects. Here's an example of how i'm learning it(a previous project):

                        Code:
                        #include <iostream>
                        using namespace std;
                        
                        int main&#40;&#41;
                        &#123;
                        	int years, months, days;
                        	cout<<"How many years old are you? ";
                        	cin>>years;
                        	cout<<endl;
                        	cout<<"How many months past your years are you? ";
                        	cin>>months;
                        	cout<<endl;
                        	cout<<"How many remaining days old are you? ";
                        	cin>>days;
                        	cout<<endl;
                        	cout<<"The numbers you entered are "<<years<<" for years, "<<months<<" for remaining months, and "<<days<<" for days. ";
                        	cout<<endl;
                        	int totalMonths, totalDays;
                        	totalMonths=years*12+months;
                        	totalDays=years*360+days;
                        	cout<<"You are approximately "<<totalMonths<<" months old. ";
                        	cout<<endl;
                        	cout<<"You are approximately "<<totalDays<<" days old. ";
                        	cout<<endl;
                        
                        	return 0;
                        &#125;

                        Comment

                        • GuidoHunter
                          is against custom titles
                          • Oct 2003
                          • 7371

                          #27
                          RE: Re: RE: Re: C++ Help

                          So just move my code around. The only thing that's structurally different from what you just posted and what I posted is you using int main() and me using void main(), which won't make a difference and you shouldn't worry about (unless you're returning 0 in void main or something).

                          Like I said, rearrange all of my body however you wish to follow whatever format you want. You say what I posted isn't coded like your older project, but I don't see a difference that would matter.

                          If you got a syntax error, tell us what it is.

                          --Guido


                          Originally posted by Grandiagod
                          Originally posted by Grandiagod
                          She has an asshole, in other pics you can see a diaper taped to her dead twin's back.
                          Sentences I thought I never would have to type.

                          Comment

                          • QreepyBORIS
                            FFR Player
                            • Feb 2003
                            • 7454

                            #28
                            RE: Re: RE: Re: C++ Help

                            How could they not get an error with code like that? They never declared any variables. XD

                            I would imagine that they would, though.

                            Signature subject to change.

                            THE ZERRRRRG.

                            Comment

                            • JurseyRider734
                              lil j the bad b-word
                              • Aug 2003
                              • 7506

                              #29
                              RE: Re: RE: Re: C++ Help

                              Hi again. I need help with some other program...I have what I did saved on floppy disk but I forgot that I don't have a floppy drive >_>

                              Anyways, I use Microsoft Visual Basic thing...so that's what it has to input into. Here's the thing.

                              Write a program that prompts the user to input x-y coordinate of a point in a Cartesian Plane. The program should output a message indicating whether the point is on the origin, x or y axis, or in a particular quadrant.

                              I'm pretty sure you have to do the if stuff, etc. Anyone who can help me do it for my class tomorrow morning gets a present >_>
                              Originally posted by Arch0wl
                              I'd better be considering I own roughly six textbooks on logic and have taken courses involving its extensive use

                              Originally posted by Afrobean
                              Originally Posted by JurseyRider734
                              the fact that you're resorting to threatening physical violence says a lot anyway.
                              Just that you're a piece of shit who can't see reason and instead deserves a fucking beating.

                              Comment

                              • talisman
                                Resident Penguin
                                FFR Simfile Author
                                • May 2003
                                • 4598

                                #30
                                RE: Re: RE: Re: C++ Help

                                uh here's the logic, not the language:

                                input x, input y
                                if x==0 and y==o
                                then output "origin"
                                if x==0 and y!=0
                                then output "x-axis"
                                if y==0 and x!=0
                                then output "y-axis"
                                if x > 0 and y > 0
                                then output "first quadrant"
                                if x < 0 and y > 0
                                then output "second quadrant"
                                if x<0 and y<0
                                then output "third quadrant"
                                if x>0 and y<0 then output "fourth quadrant"

                                fairly tedious. I'm sure there's a sexier way to do it.

                                Comment

                                Working...