CG Technical Area > Programming

C++ post your shitt

<< < (3/3)

Blackllama:
Me two years ago is just eww. I don't need to see this shit.

Burgers-13:
idk  ,, but i was just posting  where i thought  talking about c++ might go and maybe get some pointers... ima go sit in my darkest corner now  :-[

Christovski:

--- Quote from: Burgers-13 on October 30, 2013, 02:21:00 PM ---idk  ,, but i was just posting  where i thought  talking about c++ might go and maybe get some pointers... ima go sit in my darkest corner now  :-[

--- End quote ---

Don't be so afraid to start new threads Burgs :P

Leninade:

--- Quote from: Burgers-13 on October 30, 2013, 04:24:36 AM ---so taking a c++ course and im not learning diddly quawt from my teacher even tho shes really nice.. i have resorted to youtube and online help which is helping but it could only go so far..

im a total noob and im trying to make something as simple as a calculator for a food charge ex:

should ask you for the food charge and calculate the amount of a 18% tip and 7% sales tax and the toTAL.


this is what i have so far:


#include <iostream>
using namespace std;

int main()
{
   cout << "Enter charge for the food \n";
   const double PERCENT_TIP = 0.18;
      system("pause");
      return 0;
}


i dont know what function i put or how to put in the percentages into the code.  probably did that wrong helpeth

--- End quote ---
First off, you need an int for your original input variable.
Second, you need to use the cin function to allow for input from the command window. The syntax should be something like cin >> variable_name;
Finally, you need to decide how the total is being calculated. Is the tip 18% of the original price, and the tax is 7% of that new total, or are they both applied to the original price?
 i.e. one formula would be variable_name*1.18*1.07, while the other would be something like variable_name* 1.18 + variable_name*.07.

From there, it's pretty easy. You just need to do a cout << with your variable name or whatever text you want, and you should be good.

#include <iostream>
using namespace std;

int main()
{
        int price;
        int total;
        const double PERCENT_TIP = 0.18;
        const double TAX = .07
   cout << "Enter charge for the food \n";
        cin >> price >> \n;
        total = price*PERCENT_TIP + price*TAX  + price;
        cout << "The final total is: " << total << \n;
   
      system("pause");
      return 0;
}


Arrows on the cin/cout might be backwards, but I don't have a compiler to make sure, and it's an easy fix. Also, when you write code, make sure you do all your variable/const/define declarations at the top of your program. I think you can declare stuff mid-program in something like MATLAB, but I don't think C++ really lets you do that, and even if it does, it's not good practice to do that.

Navigation

[0] Message Index

[*] Previous page

Go to full version