# C++ help



## freaksavior (Mar 8, 2009)

I have 3 programs i have to build for class. one is were a kid has a summer job, he works x amount of hours and is paid x amount of dollars. find his pay before and after taxes if taxes is 14%. after taxes he spends 10% of his net income. 10% to buy school supplies. 25% for savings bonds.  his parents will pay .50 for each dollar he spends on savings bonds.

write a program to output 
Your income before and after taxes
the money you spend on clothes and accoreis (10%)
The money you spend on school supplies
the money you spend to buy savings bonds
The money your parents spend to buy additional savings bonds.

this is what i have 


```
// Summer Job
// 03-09-2009
// This program claculates the % rate and final amount
//====================== Preporcesorr directive =============================

#include <iostream>
#include <cmath>

using namespace std; 

	int main ()
{
	int	a, b, c, d, e, f, g;
	cout<<"input variables seperated by spaces. Number of hours worked x the pay + 14%" << endl;
	cin>> a >> b;
	cout << a * b<<endl;
	cin>> a >> b >> c; 
	cout << a * b * c <<endl;
	cin>> a >> b >> c >> d;
	cout << a * b * c * d<<endl;
	cin>> a >> b >> c >> d >> e;
	cout << a * b * c * d * e<<endl;
	cin >> a >> b >> c >> d >> e >> f;
	cout << a * b * c * d * e * f<<endl;
	cin >> a >> b >> c >> d >> e >> f >> g;
	cout << a * b * c * d * e * f * g;

	cout <<"press return to continue" <<endl;
	cin >> g;
	  return 0;

 }
```

basically my problem is i need to input a percentage and once i do it closes the program. how do i fix this!?

i think i need to put double c;  in there but once i do it failes the app


----------



## dazed554 (Mar 10, 2009)

Are you trying to input the percentage with the % sign? If so that may be causing the problem. If you want to get an integer value you have to enter it without the sign.

Just a tip, try to use meaningful variable names ex. hours, pay not just letters. This will help others reading your programs be able to help you and when your programs become more lengthy it will help you as well.


----------



## Wastedslayer (Mar 17, 2009)

Here you go:

#include <iostream.h>
#include <iomanip.h>

void main()
{
  double hours,rate, beforeTax, afterTax, spend1, spend2, spend3, parents;

  cout << "Input the Hours worked and your pay rate seperated by a space: " << fixed << setprecision(2);

  cin >> hours >> rate;
  beforeTax = hours*rate;
  afterTax  = beforeTax*.86;

  cout << "Your income is: " << beforeTax << endl
       << "After taxes you make: " << afterTax << endl;

  spend1 = afterTax*.90;
  spend2 = spend1*.90;
  spend3 = spend2*.75;
  parents= spend3*.50;

  cout << "If you spend 10% you have " << spend1 << "left." << endl
       << "Then if you spend 10% on school supplies you have " << spend2 << " left." << endl
       << "25% on school supplies leaves you with " << spend3 <<" left." << endl
       << "Your parents will buy an additional " << parents << " in savings bonds.";

}

//The code is kinda messy with my math but it will do


----------



## Oliver_FF (Mar 17, 2009)

In C and C++ there is a scanf function:


```
int a;
scanf("%i%%", &a);
cout << a << "%";
```
should read any input of the form "x%" where x is a number and stick that number in 'a'.

More here:
http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html


----------



## freaksavior (Mar 18, 2009)

new problem. someone im me need help quick


----------



## freaksavior (Apr 6, 2009)

Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate.  The program should then output each candidate’s name, the number of votes received, and the percentages of the total votes received by the candidate.  Your program should also output the winner of the election.
a.	Your program should use a function to read data.
b.	Your program should use another function to sort data based on Candidates name (From A to Z).
c.	Then sort it by Vote they received (From highest to lowest).
d.	Finally sort it by percentage of vote each candidate they received (From highest to lowest).
e.	Each time you need to print it to an output file calls it output.txt, make sure you append it to previous output.
f.	A sample output is below

============================== Original Data: ======================
Candidate 		Votes Received	% of Total Votes

Johnson	5000	25.91
Miller	4000	20.73
Duffy	6000	31.09
Robinson	2500	12.95
Ashton	1800	9.33

Total	19300

======================= Sorted by Candidate Name: ===================
	Candidate 	Votes Received	% of Total Votes

Ashton	1800	9.33
Duffy	6000	31.09
Johnson	5000	25.91
Miller	4000	20.73
Robinson	2500	12.95

Total	19300		

=========== Sorted by Candidate votes Received & % of total vole ===========
Candidate 	Votes Received	% of Total Votes

Duffy		6000		31.09	
Johnson		5000		25.91	
Miller		4000		20.73	
Robinson		2500		12.95	
Ashton		1800		9.33

Total		19300			




omg i have no idea how to start this. its my hw for the next week


----------



## freaksavior (Apr 13, 2009)

any1? i'll even pay you to do it.


----------



## freaksavior (Apr 20, 2009)

Still looking for some help. its due on wednesday

i have this already

//
//Lab 7 part 1
//04-12-09

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
ifstream in;

const int size = 15;

void getarray (string name [], int grade[], int max);
void printarray(string name [], int grade[], int max);
void sort(string name[], int grade[], int max);

void main ()
{
	int grade[size]={0};
	string name[size];

	in.open ("E:\\in.txt");

	getarray(name, grade, size);

	cout<<"This is the array before sorting"<<endl;
	printarray(name, grade, size);

	sort(name, grade, size);

	cout<<"This is the grades after sorting"<<endl;
	printarray (name, grade, size);

	in.close();
}
// ========================Get the code for grade and name =========================
void getarray (string name [], int grade[], int max)
{
	for(int i=0; i<max; i++)
		in>>name_>>grade;
}
// =================Sort the grades and names ======================================
void sort(string name[], int grade[], int max)
{
	for (int pass= 0; pass <max; pass++)
	{
		for (int index = 0; index<max-1; index++)
			if (grade[index] > grade[index+1])
			{
				int temp =grade[index];
				string nametemp =name[index];
				grade[index]=grade[index+1];
				name[index]=name[index+1];
				grade[index+1]=temp;
				name[index+1]=nametemp;
			}
	}
}
//====== print the grades ============

void printarray(string name [], int grade[], int max)
{
	cout<<"_-_-_-_-_-_-_-_-_-_-_-_-_-_-"<<endl;
	for(int i=0; i<max; i++)
		cout<<name<<grade<<endl;
	cout<<"-----________-----------"<<endl;
}


i think thats close to what its asking_


----------

