Hack Forums
[C] [HELP] Something wrong in my code( works for first part of problem) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] [HELP] Something wrong in my code( works for first part of problem) (/showthread.php?tid=4479023)



[HELP] Something wrong in my code( works for first part of problem) - Gun94 - Oct 6, 2014

Trying to get this program to work for my CSI class but keep getting an error. The task was to add up a collection amount of pennies(135), nickels(321), dimes(573), Quaters(857).

I need to code it to display the total amount $(float)
then show 24% going to david (d)
then show 76% going to office (d)

from my understand i labeled my variables correctly

works fine for adding total $ amount but not when i try to do the 24% and 76% of total. Any help would be appricated as i am new to using c++


Code
#include <cstdlib>
#include <iostream>

using namespace std;

//Calculates the daily dollar amount of Quarters, Dimes, Nickels, and Pennies collected and gives 25% to David and 76% to the office//
main()
{
      int num1=135, num2=321, num3=573, num4=857;
      float p=0.001, n=0.005, d=0.10, q=0.25, sum, parking=.75, david=.25;
    cout << "Enter the amount of pennies\n";
    cin >> num1;

    cout << "Enter the amount of nickels\n";
    cin >> num2;

    cout << "Enter the amount of dimes\n";
    cin >> num3;
    
    cout << "Enter the amount of quaters\n";
    cin >> num4;

    sum=p*num1 + n*num2 + d*num3 + q*num4; //"Total Amount Collected"//

    cout << "The answer is \n\n" << sum;

    cin >> parking
        parking=p*num1 + n*num2 + d*num3 + q*num4/.75

    cout << "The answer is \n\n" << parking;

    cin >> david
      
      david=p*num1 + n*num2 + d*num3 + q*num4/.25
    cout << "The answer is \n\n" << david;


}

i was able to get the code to work. now closed