Friday, July 31, 2009

C ++ help please!!?

3. For the following program write the output:


int function1 (int a, int%26amp; b, char ch = 'I')


{


cout%26lt;%26lt;a-b%26lt;%26lt;" "%26lt;%26lt;ch%26lt;%26lt;endl;


b = a - b;


return b;


}





double function1 (double x, int b, char ch = 'I')


{


cout%26lt;%26lt;x+b%26lt;%26lt;" "%26lt;%26lt;ch%26lt;%26lt;endl;


return x + b;


}





double function1 (double%26amp; x, double y, char ch = 'D')


{


cout%26lt;%26lt;x+y%26lt;%26lt;" "%26lt;%26lt;ch%26lt;%26lt;endl;


x = x + y;


return x;


}





double function1 (int a, double x, char ch = 'D')


{


cout%26lt;%26lt;x+a%26lt;%26lt;" "%26lt;%26lt;ch%26lt;%26lt;endl;


return x + a;


}





int main()


{


double db1 = 1.5, db2 = 2.5;


int in1 = 3, in2 = 7;





in1 = function1(in1, in2, 'J'); //1. ________


cout %26lt;%26lt;in1%26lt;%26lt;endl; //2. ________


cout %26lt;%26lt;in2%26lt;%26lt;endl; //3. ________


db2 = function1(db1, in1); //4. ________


cout%26lt;%26lt;db2%26lt;%26lt;endl; //5. ________


function1(1, 1.5); //6. ________


in2 = function1(db2, 1.5, 'K'); //7. ________


}








Can you please help me write the outputs? Thanks

C ++ help please!!?
This is your output:





-4 J


-4


-4


-2.5 I


-2.5


2.5 D


-1 K
Reply:-4J


-4


7


4.5I


4.5


2.5I


error or some compiler can give 3K

bottle palm

C++ help! when i build the solution and try to test it,....?

the output disappear without letting me check if it's right or not. how can i make it to stay? i am usin microsoft visual studio 2005.





this is my code:





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::fixed;


using std::setprecision;





int main()


{


//declare variables


int registrants = 0;


int fee = 0;





//enter input


cout %26lt;%26lt; "Enter number of registrants: ";


cin %26gt;%26gt; registrants;





//calculate and display order price





cout %26lt;%26lt; fixed %26lt;%26lt; setprecision(2);





if (registrants %26gt; 0)


{


if (registrants %26gt; 1 %26amp;%26amp; registrants %26lt;= 4)


cout %26lt;%26lt; "Seminar Fee: $" %26lt;%26lt; registrants * 100 %26lt;%26lt; endl;


else if (registrants %26gt;= 5 %26amp;%26amp; registrants %26lt;= 10)


cout %26lt;%26lt; "Seminar Fee: $" %26lt;%26lt; registrants * 80 %26lt;%26lt; endl;


else if (registrants %26gt; 11)


cout %26lt;%26lt; "Seminar Fee: $" %26lt;%26lt; registrants * 60 %26lt;%26lt; endl;


//endifs


}


else


cout %26lt;%26lt; "Invalid Data" %26lt;%26lt;endl;


return 0;


} //end of main function

C++ help! when i build the solution and try to test it,....?
The common solutions seem to be using getch() or system("pause") in the correct place to hold the terminal window open while you examine the output.





If you are not just a Windows drone, a more portable solution is to include and call a function something like the below at the proper point(s) in your program.





// A simple debugging routine to use with DOS console apps to hold the DOS box open


void HoldConsole(void)


{


char hold[3];





cout %26lt;%26lt; "\nHit %26lt;Enter%26gt; ";


cin.getline(hold, sizeof(hold), '\n');


cout %26lt;%26lt; endl;


}
Reply:Put in some wait-for-keyboard-input code to pause the execution.





Hope that helps.
Reply:insert the statement





getch();





one line before return 0; ... and don't forget to include the library conio.h


Please help me! Something is wrong with my C++ program?

// bla bla


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


using namespace std;


int main()





{





int seconds;


double distance;


int choice;





const double CarbonDioxide = 258.0;


const double Air = 331.5;


const double Helium = 972.0;


const double Hydrogen = 1270.0;





cout %26lt;%26lt; "\t\tSelect the disired gas\n\n";


cout %26lt;%26lt; "1. Carbon Dioxide\n";


cout %26lt;%26lt; "2. Air\n";


cout %26lt;%26lt; "3. Helium\n";


cout %26lt;%26lt; "4. Hydrogen\n";


cout %26lt;%26lt; "5. Quit\n";


cin %26gt;%26gt; choice;








if (choice == 1)


{


cout %26lt;%26lt; "enter seconds ";


cin %26gt;%26gt; seconds;


if (seconds %26lt; 0 || seconds %26gt; 30)





{


cout %26lt;%26lt; "You must enter seconds\n";


cout %26lt;%26lt; "that are in the range\n";


cout %26lt;%26lt; "of 0-30." %26lt;%26lt; endl;


}


else if (seconds %26gt; 0 || seconds %26lt; 30)


distance = seconds * CarbonDioxide;


cout %26lt;%26lt; "The total distance was.." %26lt;%26lt; distance %26lt;%26lt; endl;


}


else if (choice == 2)


{


cout %26lt;%26lt; "enter seconds ";


cin %26gt;%26gt; seconds;


if (seconds %26lt; 0 || seconds %26gt; 30)


{


cout %26lt;%26lt; "You must enter secon

Please help me! Something is wrong with my C++ program?
Yes what is happening is that this line:


distance = seconds * CarbonDioxide;


gets executed only if this condition evaluates to true:


if (seconds %26gt; 0 || seconds %26lt; 30)





Now what happens if it doesn't and you try to use the value inside distance?





A quick solution to the problem would be to replace


this:


double distance;


with this:


double distance = 0;
Reply:You misspelled 'desired'.


Shortening this C++ program?

#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


#include %26lt;ctime%26gt;


using namespace std;


using std::srand;





int main(int argc, char *argv[])


{


float b, n, wa, ga, ra, ta, tries;





cout %26lt;%26lt; "This is slots"%26lt;%26lt;endl;


ta = 1000;


cout %26lt;%26lt; "You have " %26lt;%26lt; ta %26lt;%26lt; " tokens" %26lt;%26lt;endl;


n = 10;


while (n %26gt; 0)


{


cout %26lt;%26lt; "you can play " %26lt;%26lt; n %26lt;%26lt; " times" %26lt;%26lt;endl;


cout %26lt;%26lt; "How much do want to wager:";


cin %26gt;%26gt; wa;





while (wa %26gt; ta)


{


cout %26lt;%26lt; "That is not a valid wager" %26lt;%26lt; endl;


cout %26lt;%26lt; "enter a valid wager:" %26lt;%26lt; endl;


cin %26gt;%26gt; wa;


}





while (wa %26lt;= ta - ta)


{


cout %26lt;%26lt; "That is not a valid wager" %26lt;%26lt; endl;


cout %26lt;%26lt; "enter a valid wager:" %26lt;%26lt; endl;


cin %26gt;%26gt; wa;


}

Shortening this C++ program?
since the two while conditions do the same thing, combine them into one condition:





while(wa %26gt; ta || wa %26lt;=ta-ta)


{


cout %26lt;%26lt; "that is not a valid wager." %26lt;%26lt;endl;


cout%26lt;%26lt; "Enter a valid wager."%26lt;%26lt;endl;


cin %26gt;%26gt;wa;


}





And then combine your other conditions:





if(ga %26lt; 1 || ga %26gt; 10)


{


cout %26lt;%26lt;"That is not between 1 and 10" %26lt;%26lt;endl;


cout %26lt;%26lt;"Enter a value between 1 and 10" %26lt;%26lt;endl;


cin %26gt;%26gt; ga;


}


C++ help me please?

Here's my code:





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


int i = 0, max = 0, sum = 0;


char indicator = 'y';


cout%26lt;%26lt;"Please enter number 5: "; cin%26gt;%26gt;max;


cout%26lt;%26lt;endl;


for(i=1; i%26lt;=max; i++)


sum+=i;


cout%26lt;%26lt;endl


%26lt;%26lt;"The Sum is = "%26lt;%26lt;sum%26lt;%26lt;endl;


cout%26lt;%26lt;"Do you wish to display the odd sum?"%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter y for yes, (n to end)"; cin%26gt;%26gt;indicator;


if(indicator=='y')


{


for(i=1; max%26lt;=max; i=1+2)


sum=sum+i;


cout%26lt;%26lt;endl


%26lt;%26lt;"The odd sum is = "%26lt;%26lt;sum%26lt;%26lt;endl;


}


cout%26lt;%26lt;"Okay Bye"%26lt;%26lt;endl;


return 0;


}





The answer for the 1st sum is correct 15


But the Odd sum answer should be 9 and it's aint displaying and wrong answer.

C++ help me please?
You forgot to re-initialize sum. It's adding 9 to 15 and giving you 24, right? And yeah, I missed it, but you also need to have i = i + 2, not i = 1 + 2.





if(indicator=='y')


{


sum = 0;


for(i=1; max%26lt;=max; i=i+2)


sum=sum+i;


cout%26lt;%26lt;endl


%26lt;%26lt;"The odd sum is = "%26lt;%26lt;sum%26lt;%26lt;endl;


}
Reply:for(i=1; max%26lt;=max; i=1+2)





That is very wrong there, check your study material what is not right.
Reply:I never got to C++, but do you want i=3 or do you want i=i+2?


Your line is:


for(i=1; max%26lt;=max; i=1+2)


, which would always make i=3.
Reply:Yeah, i have to agree with some of the other answers.





sum needs to be reinitialized to 0 before the second for loop.





the second for loop looks funky to me. Especially the condition max%26lt;=max and i=1+2.
Reply:Two problems:





You need to add a line that zeros your sum for the second accumulation:





if(indicator=='y')


{


sum=0; // NEW LINE TO RESET SUM


for(i=1; max%26lt;=max; i=1+2)








And the line :





for(i=1; max%26lt;=max; i=1+2)





Needs to be re-written:





for(i=1;i%26lt;=max;i+=2) // NOT max%26lt;=max and NOT i=1+2

magnolia

C++: How would I print the 5 middle numbers?

#include %26lt;iostream.h%26gt;


#include %26lt;iomanip.h%26gt;


#include %26lt;ctype.h%26gt;


#include %26lt;stdlib.h%26gt;





using namespace std;





float findMiddleOne(float,float,float,float,fl...


float findFirst(float,float,float,float,float,...


float findLast(float,float,float,float,float,f...





int main ()


{


string name;


float score1,score2,score3,score4,score5,score...


float firstlowest=0;


float lastlargest=0;


float difficulty;


cout %26lt;%26lt; "Enter the divers name: ";


getline (cin,name);


cout %26lt;%26lt; "Enter the degree of difficulty for "%26lt;%26lt;name%26lt;%26lt;"'s dive: ";


cin %26gt;%26gt; difficulty;


while (difficulty%26lt;1.2 ||difficulty%26gt;3.8)


{


cout %26lt;%26lt; "Such difficulty does not exist, please try again: ";


cin %26gt;%26gt; difficulty;


}


cout%26lt;%26lt;"Enter the seven judges' scores"%26lt;%26lt;endl;


cout%26lt;%26lt;"First score: ";


cin %26gt;%26gt; score1;


while (score1%26lt;0||score1%26gt;10)


{


cout %26lt;%26lt; "Wrong number, please try again: ";


cin %26gt;%26gt; score1;


}


cout %26lt;%26lt;"Second score: ";


cin %26gt;%26gt; score2;

C++: How would I print the 5 middle numbers?
Your code is way too complex for such a simple problem.





You can use a 7-cell array to store the scores. Much more efficient code:





string names;


float scores[7];


int i;


float score;


float difficulty = 0;





while(difficulty %26lt; 1.2 || difficulty%26gt;3.8) {


cout %26lt;%26lt; "Enter the degree of difficulty for " %26lt;%26lt; name %26lt;%26lt; "'s dive:" %26lt;%26lt; endl;


cin %26gt;%26gt; difficulty;


}





for(i = 0 ; i %26lt; 7; i++) {


score = -1;


while(score %26lt; 0 || score %26gt; 10) {


cout %26lt;%26lt; "Enter the score from judge " %26lt;%26lt; i + 1 %26lt;%26lt; endl;


cin %26gt;%26gt; score;


}


scores[i] = score;


}





Just pass the 7-array score to functions to find max and min:





float getMaxScore(float scores[], int size) {


float result = 0;


float score;


int i;


for(i = 0; i %26lt; size; i++) {


if(scores[i] %26gt; result) {


result = scores[i];


}


}


return result;


}





float getMinScore(float scores[], int size) {


float result = 100;


float score;


int i;


for(i = 0; i %26lt; size; i++) {


if(scores[i] %26lt; result) {


result = scores[i];


}


}


return result;


}





Back in your main:





float maxScore, minScore;


maxScore = getMaxScore(scores, 7);


minScore = getMinScore(scores, 7);





cout %26lt;%26lt; "The highest score was " %26lt;%26lt; maxScore %26lt;%26lt; endl;


cout %26lt;%26lt; "The lowest score was " %26lt;%26lt; minScore %26lt;%26lt; endl;


cout %26lt;%26lt; "The other five scores are: ";


for(i = 0; i %26lt; 7; i++) {


if(scores[i] != maxScore %26amp;%26amp; scores[i] != minScore) {


cout %26lt;%26lt; scores[i] %26lt;%26lt; " ";


}


}


cout %26lt;%26lt; endl;


C++ help!!! i am getting these errors and don't know how to fix them - first time working with C++?

ok, the user types item number - the program displays the color of the item. like: 12b45 or abg44. the third character determines the name of the color. which in this instance will be: blue and green. THIS IS MY CODE:


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cctype%26gt;





using namespace std;





int main()


{


//declare variables


string itemNum = "";


int location = 0;





//get input from user


cout %26lt;%26lt; "Enter an item number: " %26lt;%26lt; endl;


cin %26gt;%26gt; itemNum;





//calculate shipping charge


while (itemNum != "x" %26amp;%26amp; itemNum != "X")


{


if (itemNum.length() != 5)


cout %26lt;%26lt; "The item number must contain five digits! " %26lt;%26lt; endl;





else if( 'B' == toupper(itemNum[2])


{


cout %26lt;%26lt; "Your color is Blue" %26lt;%26lt;endl;





else if ('G' == toupper(itemNum[2])


{


cout %26lt;%26lt; "the color is green" %26lt;%26lt; endl;





else


cout %26lt;%26lt; "Invalid item!" %26lt;%26lt;endl;


}


}


}

C++ help!!! i am getting these errors and don't know how to fix them - first time working with C++?
You are missing right parenthesis. you have


else if( 'B' == toupper(itemNum[2])





if you take notice, you have two left parenthesis in that line, but only one right one. you need to have a left and right parenthesis around itemNum[2], like you do.... but you need to have parenthesis around the entire 'if' conditional. you have the one on the left, but your forgot the one on the right. In C++, anytime you have a left bracket or parenthesis, you must have a matching right bracket or parenthesis.


so make the line:


else if( 'B' == toupper(itemNum[2]))





You do this another location as well. Change that line too.





You are putting curly braces at the wrong places.





You have:





if(conditional)


code


else if(conditional


{


code


else if( conditional)


{


code


else


code


}


}


}





It should be:


if(conditional)


{


code


}


else if(conditional)


{


code


}


else if(conditional)


{


code


}


else


{


code


}





you see the difference? you are putting them at the end of all the conditionals. The curly brackets are used to separate blocks of code. They say if this condition is met, carry out all of the code between these brackets. The brackets are also why you are getting an error stating you have an else without a matching if statement. If you look at how the brackets are placed you have blocks of code that have 'else' statements without an 'if' statement before it in that block of code. So change the placement of the curly brackets and those problems should go away.





Take note, if you are only doing one statement after an 'if' or 'else if', then you do not need curly brackets. if you have more than one statement that needs to be executed if a condition is met, then you need curly brackets. I often put them in even if I only have one statement after an 'if' conditional because it keeps the code clean and it is easy to add more lines in the future if I discover i need to do so.
Reply:#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cctype%26gt;





using namespace std;





int main()


{


//declare variables


string itemNum = "";


int location = 0;





//get input from user


cout %26lt;%26lt; "Enter an item number: " %26lt;%26lt; endl;


cin %26gt;%26gt; itemNum;





//calculate shipping charge


while (itemNum != "x" %26amp;%26amp; itemNum != "X")


{


if (itemNum.length() != 5)


{


cout %26lt;%26lt; "The item number must contain five digits! " %26lt;%26lt; endl;


}


else if( 'B' == toupper(itemNum[2])) %26lt;%26lt;- Added ')'


{


cout %26lt;%26lt; "Your color is Blue" %26lt;%26lt;endl;


} %26lt;%26lt;- Added '}'


else if ('G' == toupper(itemNum[2])) %26lt;%26lt;- Added ')'


{


cout %26lt;%26lt; "the color is green" %26lt;%26lt; endl;


} %26lt;%26lt;- Added '}'


else


cout %26lt;%26lt; "Invalid item!" %26lt;%26lt;endl;


cout %26lt;%26lt; "Enter an item number: " %26lt;%26lt; endl;


cin %26gt;%26gt; itemNum;


} // Removed the extra }} and moved input within loop


return 0;


} //end of main function





This code should work now.
Reply:Both lines that begin with "else if" need a ) at the end. This is, by the way, explicitly stated in the error message you provided.





You are also missing closing braces after each of your else blocks.
Reply:find another profession, programming doesn't seem to be your strong skill..


Please HELP, I have a logical error in C++!?

My Prof, requires that 1 isn't a prime number, my prog is returning 1 as a prime!


Please Help!





// Selection 3 Test a Number to see if it is Prime or Perfect!!!


else if (selection ==3)


{


while (ans=='y')


{


cout%26lt;%26lt;"Test a Number to See if it is Prime or Perfect"%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter any Number Between 1 and 1000, Then Press 'Enter'"%26lt;%26lt;setw(2)%26lt;%26lt;":";


cin %26gt;%26gt;num;


cin.clear();


cin.ignore(100, '\n');


if (num%26gt;=1 %26amp;%26amp; num%26lt;=1000) //Validate input


{


cout%26lt;%26lt;"The Divisors for "%26lt;%26lt;num%26lt;%26lt;" are"%26lt;%26lt;endl;


squrt=sqrt(num);


for (divisor1=1,sum=0 ; divisor1%26lt;squrt ; divisor1++)//Formulate the output


{


if (num % divisor1==0)


{


divisor2=num/divisor1;


cout%26lt;%26lt;setw(58)%26lt;%26lt;divisor1%26lt;%26lt;" and "%26lt;%26lt;divisor2%26lt;%26lt;endl;


sum=sum+divisor1;


if (divisor1!=1)


{


sum=sum+divisor2;


}


}


}


if (divisor1==squrt)


{


cout%26lt;%26lt;setw(58)%26lt;%26lt;squrt%26lt;%26lt;endl;


sum=sum+squrt;


}


cout%26lt;%26lt;"The Number you Entered "%26lt;%26lt;num%26lt;%26lt;" is ";


if (sum ==1)


{


cout%26lt;%26lt;"a Prime Number"%26lt;%26lt;endl;


}


else if (sum==num)


{


cout%26lt;%26lt;"a Perfect Number"%26lt;%26lt;endl;


cout%26lt;%26lt;"the Sum of the Divisors is "%26lt;%26lt;sum%26lt;%26lt;endl;


}


else


{


cout%26lt;%26lt;"Not Prime or Prefect"%26lt;%26lt;endl;


cout%26lt;%26lt;"the Sum of the Divisors is "%26lt;%26lt;sum%26lt;%26lt;endl;


}


cout%26lt;%26lt;"If You Would Like to Test Another Number Press 'y', Otherwise Press Any Key"%26lt;%26lt;endl;


cin%26gt;%26gt;ans;


cin.clear();


cin.ignore(100, '\n');


}


else


{


cout%26lt;%26lt;"ERROR Invalid Number, Your Number MUST be Between 1 and 1000"%26lt;%26lt;endl;


}


}


}

Please HELP, I have a logical error in C++!?
If he doesn't want to see 1, then omit 1





I would include in your code comments that similar to this:





1 is mathematically a prime number,


but is being omitted per Professor Smith's instruction





As a programmer, I have included comments when I disagree with the requirements. as it serves as a bookmark for me or someone else should the end user requirements change.


Help me with a C++ program that I have created. the assignment: write a program that promts the user to?

enter 3 srings.The program outputs the 6 permutation of those strings. When i run my progr. permutation appears scattered. I want the permuations to appear like this


abc


cba


bca (in order)





my program:





**************************************...


This program outputs the six permutations of a string


**************************************...


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int main()


{


string word1;


string word2;


string word3;





cout %26lt;%26lt; "Enter a word: ";


cin %26gt;%26gt; word1;


cout %26lt;%26lt; "Enter a second word: ";


cin %26gt;%26gt; word2;


cout %26lt;%26lt; "Enter a third word: ";


cin %26gt;%26gt; word3;





cout %26lt;%26lt; "The permutation of the words you enter are: " %26lt;%26lt; endl;





cout %26lt;%26lt; word3 %26lt;%26lt; word2 %26lt;%26lt; word1 %26lt;%26lt;endl;


cout %26lt;%26lt; word2 %26lt;%26lt; word1 %26lt;%26lt; word3 %26lt;%26lt;endl;


cout %26lt;%26lt; word1 %26lt;%26lt; word3 %26lt;%26lt; word2 %26lt;%26lt;endl;


cout %26lt;%26lt; word3 %26lt;%26lt; word1 %26lt;%26lt; word2 %26lt;%26lt;endl;


cout %26lt;%26lt; word1 %26lt;%26lt; word3 %26lt;%26lt; word2 %26lt;%26lt;endl;


cout %26lt;%26lt; word3 %26lt;%26lt; word1 %26lt;%26lt; word2 %26lt;%26lt;endl;


return o;


}

Help me with a C++ program that I have created. the assignment: write a program that promts the user to?
1'st tell me in which standard u r,bcoz i am also having c++.i want 2 know ur level 1'st tan may b i can help u.

forsythia

Im having some compilerproblems in c++ its a very simple program im a complete noob to this pleace help?

#include %26lt;iostream%26gt;


#include%26lt;iomanip%26gt;


#include%26lt;string%26gt;


unsing namespace std:


int name()


{


string en //Employee name


hw, //Hours Worked


hr, //Hourly Rate


tw, //Total Wages


fe, //Federal Withholdings


sw, //State Withholdings


h, //Hospitalization


ud; //Union Dues


td; //Total Deduction


np; //Net Pay


cout%26lt;%26lt;fixed%26lt;%26lt;shouwpoint%26lt;%26lt;setprecision(...


cout%26lt;%26lt;"\nPlease enter Employee Name."%26lt;%26lt;endl;


cin%26gt;%26gt;en;


cout%26lt;%26lt;"\nPlease enter Hours Worked."%26lt;%26lt;endl;


cin%26gt;%26gt;hw;


cout%26lt;%26lt;%26lt;%26lt;\nPlease enter Hourly Rate"%26lt;%26lt;endl;


cin%26gt;%26gt;hr;


tw=hw*hr;


fw=(tw*18)/100;


sw=(tw*4.5)/100;


h=25.65;


ud=(tw*2)/100;


td=fw+sw+h+ud;


np=tw-td;


cout%26lt;%26lt;"Emplyee\t\t\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;...


cout%26lt;%26lt;"Hours Worked\t\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;hw%26lt;%26lt;endl;


cout%26lt;%26lt;"Hourly Rate\t\t\t\"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;hr%26lt;%26lt;\n\n;


cout%26lt;%26lt;"Deductions\n"


cout%26lt;%26lt;"Federal Withholdings\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;td%26lt;%26lt;endl...


cout%26lt;%26lt;"State Withholdings\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;sw%26lt;%26lt;endl...


cout%26lt;%26lt;"Hospitalization\t"%26lt;%26lt;":"%26lt;%26lt;setw(1...

Im having some compilerproblems in c++ its a very simple program im a complete noob to this pleace help?
Hey what error compiler is giving??


C++ program help!?

here is my code :





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int temp;





int main()


{


int numbers[5];


int counter;


char list[6][16];








cout %26lt;%26lt;"Please enter 5 numbers: ";





for (counter = 0; counter %26lt; 5; counter++)


{


cin %26gt;%26gt; numbers[counter];


}





cout %26lt;%26lt; endl;








cout %26lt;%26lt;" The numbers in reverse order are: ";





for (counter = 4; counter %26gt;=0; counter--)





cout %26lt;%26lt; numbers[counter] %26lt;%26lt; " ";


cout %26lt;%26lt; endl;








cout %26lt;%26lt;"Enter 5 words: ";


for (temp = 0; temp%26lt;6; temp++)


{


cin.get (list[temp],16);


}





cout %26lt;%26lt; list %26lt;%26lt; endl;

















return 0;


}





I need to be able to take 5 words and then display the 1st and 3rd letter of each word...im stumped...please help


the words need to be stored into a string array just cant figure out how need the extra help thanks

C++ program help!?
Since your list is a two dimensional array of type char you need only to print out something like





cout %26lt;%26lt; list[temp][1] %26lt;%26lt; list[temp][3] %26lt;%26lt; endl;





in a for loop like you have done before.





If you were using true string variables then you might have had more trouble but, even so, string variables have a method for exporting to character arrays anyway.


C++ please explain this to me?

#include %26lt;iostream.h%26gt;





#define MAX 20





main()


{





int number[MAX] = {12,33,45,66,43,1,56,78,101,99};


int index;





cout.setf(ios::right);


for (index = 0; index %26lt; MAX; index++)


{


cout %26lt;%26lt; endl


%26lt;%26lt; "THE CONTENTS OF ARRAY ELEMENT";


cout.width(4);


cout %26lt;%26lt; (index + 1) %26lt;%26lt; " IS :";


cout.width(4);


cout %26lt;%26lt; number[index];


}


cout %26lt;%26lt; endl %26lt;%26lt; endl;


return(0);


}

C++ please explain this to me?
It's pretty clear that the code prints out the contents of an array, using a loop to generate indices ranging from 0 to MAX-1. The indices are used to index the array and print each element in turn.





Go through the code carefully, and you should be able to follow it. When you find something that puzzles you, such as how arrays work, read the appropriate section of the textbook.
Reply:Ok, here we start:





// A preprocessor statement to include a header, deprecated *.h


// New format uses the '#include %26lt;iostream%26gt;'.


#include %26lt;iostream.h%26gt;


// New format would also use 'using namespace std;' here.


// Preprocessor statement to define a literal value.


#define MAX 20





// main() begins at opening brace.


main()


{





// Allocates an integer array named number with MAX(20)


// elements and initializes them here.


int number[MAX] = {12,33,45,66,43,1,56,78,101,99... // Assumes


// missing closing brace and more numbers in array above.





// Allocates another integer called index, all allocations are made


// on the stack with scope and lifetime local to main().


int index;





// This call to the cout object's setf() function sets the right


// justification flag.


cout.setf(ios::right);





// The initialization statements needed by a for loop, using MAX as


// the limit to the index value.


for (index = 0; index %26lt; MAX; index++)


{// The for loop's statement group begins at this opening brace.


// Outputs a newline to the screen and the title.


cout %26lt;%26lt; endl


%26lt;%26lt; "THE CONTENTS OF ARRAY ELEMENT";





// Cout object's width() function sets width at 4


cout.width(4);


// Outputs corrected count number for pass through the loop and


// the word 'IS' with appropriate space padding and punctuation.


cout %26lt;%26lt; (index + 1) %26lt;%26lt; " IS :";


// Cout object's width() function sets width at 4


cout.width(4);


// Outputs the current array member referred to by index.


cout %26lt;%26lt; number[index];


}// Loop returns to top here.


// Outputs two newlines to the screen.


cout %26lt;%26lt; endl %26lt;%26lt; endl;


// Since all functions in C++ are assumed to return an integer if


// no return is specified, this returns an integer to satisfy the case.


return(0);


}// Program termination here.





I hope the above line by line explanation will help you understand enough to do the next ones by yourself.


C++ programing?

Troubles with my if statements


I keep getting this error (using the bloodshed compiler)


"expected primary-expression before '%26gt;' token"





here is the code ...





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;











using namespace std;





int main()


{


int Month;


int Day;


int Year;





//month


cout%26lt;%26lt; "Please enter the Month (03): ";


cin%26gt;%26gt; Month;


if (Month %26lt; 01 %26amp;%26amp; %26gt; 12);


cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";





//day


cout%26lt;%26lt; "Please enter the Day (15): ";


cin%26gt;%26gt; Day;


if (Day %26lt; 01 %26amp;%26amp; %26gt; 31);


cout%26lt;%26lt; "Please enter a valid Day in 2 digit format\n";





//year


cout%26lt;%26lt; "Please enter the Year (2000): ";


cin%26gt;%26gt; Year;


if (Month %26lt; 1800 %26amp;%26amp; %26gt; 2999);


cout%26lt;%26lt; "Please enter a valid Year in 4 digit format\n";





cout%26lt;%26lt; "The date you entered is " %26lt;%26lt;Month%26lt;%26lt;"/"%26lt;%26lt;Day%26lt;%26lt;"/"%26lt;%26lt;Year%26lt;%26lt;"\n";





return 0;





}

C++ programing?
Instead of:





if (Month %26lt; 01 %26amp;%26amp; %26gt; 12);


cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";





You should write:





if (Month %26lt; 1 || Month %26gt; 12) {


cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";


}





1) Don't put a semicolon after the closing ).


2) Don't prefix numbers with a 0. The compiler treats these as octal numbers.


3) The expression in your if statement is incorrect.


3a) You are using %26amp;%26amp; (and) instead of || (or). A number can't be both less than 1 and greater than 12.


3b) You need to write the variable name once for each expression in your if statement.
Reply:your expression is wrong.


if (Month %26lt; 01 %26amp;%26amp; %26gt; 12);


cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";


it should be like


if (Month %26lt; 01 %26amp;%26amp; Month%26gt; 12)


cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";





correct similar mistakes.


ur syntex is incorrect.try reading some books or search google for c++ tutorial.
Reply:duh com'on --- if statements will not have """ ; """ semicolen marks .... check it out.

jasmine

C++ question,plz tell me coding to print a pyramid???

the output shoule be:





************%26amp;


*********%26amp;***%26amp;


*******%26amp;*******%26amp;


*****%26amp;***********%26amp;


***%26amp;***************%26amp;


%26amp; %26amp; %26amp; %26amp; %26amp; %26amp; %26amp; %26amp; %26amp; %26amp;





asterisks(*) are not to be printed in real pyramid.


asterisks are just the spaces.





i have made the program but the output is not right....


if i enter 10 lines, output comes only as 5 lines


and if i enter 8, results is only 4 lines:


plz help me as wt can i do?


3 minutes ago





the program i made is:


#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


int main()


{


clrscr();


int i,j,n,m=1,p=-1;


cout%26lt;%26lt;"enter the no. of rows: ";


cin%26gt;%26gt;n;


n=n+4;


cout%26lt;%26lt;"\n";


for(i=1; i%26lt;=n; i++)


{


for(j=0; j%26lt;=n; j++)


{ cout%26lt;%26lt;" "; }


n-=2;





for(j=1; j%26lt;=(2*i-m); j++)


{ cout%26lt;%26lt;"%26amp;"; }


m+=2;





for (j=1; j%26lt;=p; j++)


{ cout%26lt;%26lt;" "; }


p+=4;


if(j%26gt;1)


{ cout%26lt;%26lt;"%26amp;"%26lt;%26lt;"\n"; }


cout%26lt;%26lt;"\n";


}


getch();


return 0;


}

C++ question,plz tell me coding to print a pyramid???
The reason you're not getting the number of lines you expect, is because you're using n in the test of your for loop, and then also modifying n in the loop itself.





For example, Say you enter 10 as the number of rows you want. n gets set to 14 before the loop starts.





So for the first iteration, i is 1 and n is 14, 1 %26lt;= 14 is true.





Second iteration, n has been decremented by 2, so i is 2 and n is now 12. 2 %26lt;= 12 is true, so it continues.





Third iteration, i is 3, n is 10





Forth iteration, i is 4, n is 8





Fifth iteration, i is 5, n is 6





Sixth iteration, i is 6, n is 4. 6 is not smaller than or equal to 4, so the loop stops.





You probably need to use a separate variable there.


My c++ program has some error..so pl correct them... it is a program to count unique words and what these are?

#include%26lt;iostream%26gt; // Allows program to perform input and output


using std::cout; // program uses cout


using std::cin; // program uses cin





#include%26lt;fstream%26gt;


using std::ifstream;








int main() // function main begains program execution





{





ifstream in;


char w[2000][15];


int alphabet[26];


char ch;


int ind = 0. subind = 0;





// initialise the array with zeros





for(int i=0;i%26lt;26;i++)


alphabet[i] = 0;





//Open the input file


in.open("Text.txt");





//Check the file opened successfully.


if(!in.is_open())


cout%26lt;%26lt;"Unable to open input file."%26lt;%26lt;endl;





// Read the input file character by character


while(in.get(ch))





// if the character is an alphabet, then append the word


if( (ch%26lt;91%26amp;%26amp;ch%26gt;64)||(ch%26lt;123%26amp;%26amp;ch%26gt;96) )





{


w[ind][subind]=ch;


subind++;


}


// end if





// If a space found, move onto a new word





if(ch==' ')


{


w[ind][subind] = '\0';


subind=0;


ind++;


w[ind][subind]='\0';


} // end fi





} // end while





// Find the cout of occurence of words which starts with a letter





for(int i=0;i%26lt;ind;i++)


alphabet[toupper(w[i][0] = 65]++;





int max=0 // to find the max





// Display results





for(int i=0;i%26lt;26;i++)


if(alphabet[i]!=0)


{


// Display the cout of words that starts with a letter





cout%26lt;%26lt;"\n" %26lt;%26lt; static_cast %26lt;char%26gt; (i+65) %26lt;%26lt;"'s-"


%26lt;%26lt;alphabet[i]%26lt;%26lt;"--";





// Find for the max occurences of a letter


if (alphabet[i]%26gt;alphabet[max])


max=1;


// Display the words that starts with a specific letter





for (int j=0;j%26lt;ind;j+=)


if(toupper(w[j][0]==(i+65))


cout%26lt;%26lt;w[j]%26lt;%26lt;", ";


} // end if





// A conclusion comment of the program


cout%26lt;%26lt;"\n\nLetter with that began the most words was "


%26lt;%26lt;static_cast%26lt;char%26gt; (max+65);





// close the input file


in.close();


return 0; // indicate program executed successfully


} // end of function, main

My c++ program has some error..so pl correct them... it is a program to count unique words and what these are?
What is the output? I may be able to analyse depending upon the actual output.





I cant run it here as i do not have any C++ compiler out here


Whats wrong with this c++ program?

I need to output the sum of the square of the odd numbers between firstnum and secnum. I also need to output the sum of all the even numbers between firstnum and secnum.





#include%26lt;iostream%26gt;


#include%26lt;cmath%26gt;


using namespace std;


int main()


{


int firstnum,secnum, i, total=0, a, b;


cout%26lt;%26lt;"Enter a integer:";


cin%26gt;%26gt;firstnum;


cout%26lt;%26lt;"Enter a second integer (must be less then the first integer enterd):";


cin%26gt;%26gt;secnum;


cout%26lt;%26lt;"your enterd :"%26lt;%26lt;secnum%26lt;%26lt;endl;


if(firstnum%26lt;secnum)


cout%26lt;%26lt;endl;


else


if (firstnum%26gt;secnum)


cout%26lt;%26lt;"Please re-run program and enter numbers again"%26lt;%26lt;endl;


for (i=firstnum; i%26lt;= secnum; i++)


if(i % 2 != 0)


cout %26lt;%26lt; i %26lt;%26lt; " is an odd number between " %26lt;%26lt; firstnum %26lt;%26lt; " and " %26lt;%26lt; secnum %26lt;%26lt; endl;


cout%26lt;%26lt;"The sqrt is"%26lt;%26lt;sqrt(i)%26lt;%26lt;endl;





for (i=firstnum; i%26lt;= secnum; i++)


if(i % 2 == 0)


cout %26lt;%26lt; i %26lt;%26lt; " is an even number between " %26lt;%26lt; firstnum %26lt;%26lt; " and " %26lt;%26lt; secnum %26lt;%26lt; endl;


total += i;


cout %26lt;%26lt; "The total of all even numbers from " %26lt;%26lt; firstnum %26lt;%26lt; " to " %26lt;%26lt; secnum %26lt;%26lt; " is " %26lt;%26lt; total %26lt;%26lt; endl;


cout%26lt;%26lt;"\nPart B"%26lt;%26lt;endl;


a=1;


while(a%26lt;=10)


{


cout%26lt;%26lt;a%26lt;%26lt;" the sqrt "%26lt;%26lt;sqrt(a)%26lt;%26lt;endl;


a=a+1;


}


system("pause");


return 0;

Whats wrong with this c++ program?
There are numerous problems, but I believe these are the three most important ones:





I. It doesn't follow the specification


As written, your program looks like it was supposed to output the following:


1. The odd numbers between firstnum and secnum.


2. The square roots of those numbers.


3. The even numbers between firstnum and secnum.


4. The sum of all the even numbers between firstnum and secnum


5. The square roots of the whole numbers 1 through 10.


Of those 5 things, only one (number 4) is among the things you originally said the program is supposed to output.





II. For loops need correction


If you want several statements to be executed on each iteration of a for loop, you have to put those statements inside curly braces, like this:


for (i = firstnum; i %26lt;= secnum; i++)


{


(the statements go here)


}


Otherwise, only the first statement after the for statement is executed on each iteration of the loop.





III. Numbers aren't squared correctly


If you want the square, as opposed to the square root, of a number a, then you need to use a**2 or a*a, not sqrt(a).


C++ help! i am just a beginner - need help with my program please! i get some errors that i don't know how

this is my code:


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::fixed;


using std::setprecision;





int main()


{


//declare variables


int yearsCompany = 0;


int weekVac = 0;





//enter input


cout %26lt;%26lt; "Enter numbers of years of the employee: ";


cin %26gt;%26gt; yearsCompany;





//calculate and display the number of weeks due to an employee





cout %26lt;%26lt; fixed %26lt;%26lt; setprecision(2);





if (yearsCompany = 0)


cout %26lt;%26lt; "Years of vacation due: " %26lt;%26lt; weekVac = 0 %26lt;%26lt; endl;


else if (yearsCompany %26gt;= 1 %26amp;%26amp; yearsCompany %26lt;= 5)


cout %26lt;%26lt; "Years of vacation due: " %26lt;%26lt; weekVac = 1 %26lt;%26lt; endl;


else if (yearsCompany %26gt;= 6 %26amp;%26amp; yearsCompany %26lt;= 10)


cout %26lt;%26lt; "Years of vacation due: " %26lt;%26lt; weekVac = 2 %26lt;%26lt; endl;


else if (yearsCompany %26gt;= 11 )


cout %26lt;%26lt; "Years of vacation due: " %26lt;%26lt; weekVac = 3 %26lt;%26lt; endl;


else


cout %26lt;%26lt; "invalid years: " %26lt;%26lt; endl;


//end ifs


return 0;


} //end of main function

C++ help! i am just a beginner - need help with my program please! i get some errors that i don't know how
Start with something simple like the Hello World example.





#include %26lt;iostream.h%26gt;





main()


{


for(;;)


{


cout %26lt;%26lt; "Hello World! ";


}}
Reply:"cout %26lt;%26lt; "Years of vacation due: " %26lt;%26lt; weekVac = 0 %26lt;%26lt; endl;"





You can not set a variable in the cout statement.








You need to set it prior to use

crab apple

Using C++ .....?

My code compiles fine but how do I ADD these 3 things to my code before it says credit limit exceeded.... Can someone show me...





Account: 100


Credit Limit: 5500.00


Balance: 5894.78





Then which is already in my code Credit limit exceeded....





Here is my code:


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::fixed;





# include %26lt;iomanip%26gt;





using std::setprecision;





int main()


{


int accountNumber; // Customers account number


double balance; // Customers balance


double charges; // Charges on the account


double credits; // Credits to the account


double limit; // Credit limit on the account





cout %26lt;%26lt; "Enter account number (-1 to end): " %26lt;%26lt; fixed;


cin %26gt;%26gt; accountNumber; // Code to read customer's account number





while (accountNumber != -1) // begin loop


{


cout %26lt;%26lt; "Enter beginning balance: " %26lt;%26lt; endl; // prompt and read the customers balance


cin %26gt;%26gt; balance;





cout %26lt;%26lt; "Enter total charges: " %26lt;%26lt; endl; // prompt and read the customers charges


cin %26gt;%26gt; charges;





cout %26lt;%26lt; "Enter total credits: " %26lt;%26lt; endl; // prompt and read the customers credit


cin %26gt;%26gt; credits;





cout %26lt;%26lt; "Enter credit limit: " %26lt;%26lt; endl; // prompt and read the customers credit history


cin %26gt;%26gt; limit;





balance = balance + charges - credits; // calculate the new customers balance





if (balance + charges - credits %26gt; limit) // determine if customers credit limit is exceeded


cout %26lt;%26lt; "Credit Limit Exceeded." %26lt;%26lt; endl; // if customers limit is exceeded print message





cout %26lt;%26lt; "\nEnter account number (-1 to end): ";


cin %26gt;%26gt; accountNumber; // reading customers account number


} // End while loop....





cout %26lt;%26lt; endl; // ensure all output is displayed


return 0;


} // end main

Using C++ .....?
You already reassigned balance to equal balance + charges - credits.... so you dont need to say it again in your if statement or else it will be off.





also shouldnt it be balance PLUS credits MINUS charges?





try:


if(balance %26gt; limit)


{


cout %26lt;%26lt; "Credit Limit Exceeded."


}





make sure you bracket because your cout statement is not on the same line as your if statement.


Good Luck


Hope it Helped


R


C++ Program, it's fun but just not getting it?

#include%26lt;iostream%26gt;


#include%26lt;iomanip%26gt;


using namespace std;








int dollar, quarter, nickel,penny;


double CostOfPurchase, AmountTendered, change, CHANGE;





int main ( )


{


cout%26lt;%26lt;"Enter cost of Purchase: "%26lt;%26lt;endl;


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter amount tendered: "%26lt;%26lt;endl;


cin%26gt;%26gt; AmountTendered;


cout%26lt;%26lt;endl;








change= AmountTendered - CostOfPurchase;


cout%26lt;%26lt;"The change is $"%26lt;%26lt; change%26lt;%26lt;endl;





(int)dollar= change/1.00;


(int)quarter=(change - dollar)/0.25;


(int)nickel=(change - dollar - quarter)/0.05;


(int)penny = nickel/0.01;





cout%26lt;%26lt; dollar%26lt;%26lt;" dollar"%26lt;%26lt;endl;


cout%26lt;%26lt; quarter%26lt;%26lt;" quarter"%26lt;%26lt;endl;


cout%26lt;%26lt; nickel%26lt;%26lt; " nickel"%26lt;%26lt;endl;


cout%26lt;%26lt; penny%26lt;%26lt; " penny" %26lt;%26lt;endl;


return 0;


}





Here is my attempt at this so far. I have to make a program to make change. I can have it make the change just fine. It is making it divide the change into dollars, quarters, and nickels, pennies.

C++ Program, it's fun but just not getting it?
Your problem is here:


(int)nickel=(change - dollar - quarter)/0.05;





You have a quarter worth as much as a dollar.


If your starting amount was $1.40, then


nickle = (1.40 -1 -1)/5 = -.8





I would do it in steps. It's easier to debug.





(int)dollars= change/1.00;


change = change - dollars;





(int)quarters= change)/0.25;


change = change - .25*quarters;





(int)nickels= change/0.05;


change = change - .05 * nickels;





(int)pennys = change/0.01;
Reply:ok simply dont use any doubles! (trust me the rounding errors will be a nitemare later) use int only and work in pennies rather than dollars. The only time to use doubles with money is if you want fractional pennies say if your writing code for the stock market.





So if we rewrite one of your lines with better variable names and a few tweaks we might get:


number_of_quarters = ( change - number_of_dollarbills ) / 25;





So how can we find the bug?


We will do whats called deskchecking and try to run the program on paper and in our heads. We go though each line and try to work out what the computer will do.





So if I spend $5.67 and pay with a $10 note then:


change = 1000 - 567 = 433


number_of_dollarbills = 433 / 100 = 4


number_of_quarters = (433 - 4) / 25 and we see the bug is in treating the number of dollar bills as if it we they amount in dollars, we should have had 433 - 400 instead





BTW Thats REALLY good coding if you've only been at it for 2 weeks!


C++ help.......Back again...this time, i am kinda stuck on user defined functions. i almsot have it working...

#include%26lt;iostream%26gt;


#include%26lt;string%26gt;


#include%26lt;cctype%26gt;


using namespace std;


//getValue


int getValue(int value);


int value=0;


//getLetter


char getLetter(char letter);


char letter='y';


int main()


{


int thisYear=0;


int thisMonth=0;


int year=0;


int month=0;


int ageYear=0;


int ageMonth=0;


char again='y';


cout%26lt;%26lt;"This program asks you to enter today's year in 4 digits,\n";


cout%26lt;%26lt;"and today's month number in 2 digits.\n\n";


cout%26lt;%26lt;"Then it asks you to enter your birth year in 4 digits,\n";


cout%26lt;%26lt;"and your birth month number in 2 digits.\n\n";


cout%26lt;%26lt;"The program will calculate and display your age in years and months.\n";


cout%26lt;%26lt;getValue(thisYear);


cout%26lt;%26lt;getValue(thisMonth);


while (again=='y')


{


//assign to year value returned from getValue.


cout%26lt;%26lt;getValue(year);


//assign to month value returned from getValue.


cout%26lt;%26lt;getValue(month);


ageYear=thisYear-year;


ageMonth=thisMonth-month;


if(thisMonth%26lt;month)


{


ageYear=ageYear--;


ageMonth=ageMonth+12;


}

C++ help.......Back again...this time, i am kinda stuck on user defined functions. i almsot have it working...
where you are calling the gatValue ( year) and the other call you are passing an int down to the fuction. BUT the only getValue you have supplied takes a string as the param.





I think you want


int getValue () {


int i;


cin %26gt;%26gt; i // allow input


return(i); // and give to to the caller


}





then in your main you want


year = getValue( ) ;


cout %26lt;%26lt; year;





Good luck
Reply:Yep yep, you defined int getValue(string) and you are calling int getValue(int), so the linker is looking in all the files it is building for that function, is not finding it, and is coughing. The reason your code compiles is because you *declared* int getValue(int), but you *defined* int getValue(string).





The compiler does not actually match your function calls to the physical code, it just makes sure everything is syntactically and semantically correct. The linker does the heavy lifting of matching function calls with jumps to the right memory addresses.
Reply:int getValue(int) and ur defining method with following method name getValue(string); thats why it is giving err;


In c++ how do i get a 4 digit year to show up as 2 digits....ex, i want january 1 2367 to be 01/01/67...?

i keep getting 01/01/2367....i need to get 01/01/67





date T; // variable of new class date


T.setdate(1,1,2367);





void date::printconventional()


{


if ( month %26lt; 10)


cout %26lt;%26lt; "0";


else


cout %26lt;%26lt; "";


cout %26lt;%26lt; month %26lt;%26lt; "/";





if ( day %26lt; 10)


cout %26lt;%26lt; "0";


else


cout %26lt;%26lt; "/";


cout %26lt;%26lt; day;


if (year


if ( year %26lt; 10)


cout %26lt;%26lt; "0";


else


cout %26lt;%26lt; "/";


cout %26lt;%26lt; year;





// cout %26lt;%26lt; ( month %26lt; 10 ? "0" / "" ) %26lt;%26lt; month %26lt;%26lt; ":"


// %26lt;%26lt; ( day %26lt; 10 ? "0" / "" ) %26lt;%26lt; day;


}

In c++ how do i get a 4 digit year to show up as 2 digits....ex, i want january 1 2367 to be 01/01/67...?
Use modulo operator:





year % 100





If year is 2367, then 2367 modulo 100 is 67.
Reply:use the setprecision code. See source for examples.

strawberry

Am i doing this c++ program right?

can someone plz tell me what i'm doign wrong plzzz?





#include %26lt;conio.h%26gt;// needed for getch


#include %26lt;iostream.h%26gt;//needed for cout and cin messages


#include %26lt;string.h%26gt;//needed for string copy


#include %26lt;iomanip.h%26gt;


#include %26lt;math.h%26gt;


void startup();


void method();


int main()


{


startup();


method();


getch();


return 0;


}





void startup()


{


cout%26lt;%26lt;""%26lt;%26lt;'\n';


cout%26lt;%26lt;"jan 14, 2008"%26lt;%26lt;'\n';


cout%26lt;%26lt;"pg pro"%26lt;%26lt;'\n';


cout%26lt;%26lt;""%26lt;%26lt;'\n';


}


void method()


{


char stock[20];


int open;


int close;


int shares;


int final;


cout%26lt;%26lt;"Enter name ";


cin.get(stock, 20);


cin.ignore(80, '\n');





cout%26lt;%26lt;"enter open value ";


cin%26gt;%26gt;open;


cout%26lt;%26lt;"enter closing value ";


cin%26gt;%26gt;close;





cout%26lt;%26lt;"Enter number of stock you own";


cin%26gt;%26gt;shares;





final = close - open;





cout%26lt;%26lt;stock;


cout%26lt;%26lt;open;


cout%26lt;%26lt;close;


cout%26lt;%26lt;final;


}

Am i doing this c++ program right?
i took the time to debug it my self, heres the clean code....








#include %26lt;conio.h%26gt;// needed for getch


#include %26lt;iostream.h%26gt;//needed for cout and cin messages


#include %26lt;string.h%26gt;//needed for string copy


#include %26lt;iomanip.h%26gt;


#include %26lt;math.h%26gt;


using namespace std;





void startup();


void method();


int main()


{


startup();


method();


getch();


return 0;


}





void startup()


{


cout %26lt;%26lt; ""%26lt;%26lt;'\n';


cout %26lt;%26lt; "jan 14, 2008"%26lt;%26lt;'\n';


cout %26lt;%26lt; "pg pro"%26lt;%26lt;'\n';


cout %26lt;%26lt; ""%26lt;%26lt;'\n';


}


void method()


{


char stock[20];


int open;


int close;


int shares;


int final;


cout %26lt;%26lt; "Enter name ";


cin.get(stock, 20);


cin.ignore(80, '\n');





cout %26lt;%26lt; "enter open value ";


cin %26gt;%26gt; open;


cout %26lt;%26lt; "enter closing value ";


cin %26gt;%26gt; close;





cout %26lt;%26lt; "Enter number of stock you own";


cin %26gt;%26gt; shares;





final = close - open;





cout %26lt;%26lt; stock;


cout %26lt;%26lt; open;


cout %26lt;%26lt; close;


cout %26lt;%26lt; final;


return 0;


}








DONT FORGET TO USE PROPER TABBING.
Reply:The program runs fine on my computer. There are a few problems, though:


-- No error checking when the user inputs values (what if "abc" is inputted for the open value?)


-- The output at the end is all on the same line without any spaces, so it's not really readable


-- You can use "endl" instead of '\n' when printing a newline with cout


-- You're not doing anything with the number of shares. Is this on purpose?


-- Why do you need "math.h"?
Reply:instead of


cout%26lt;%26lt;"blah blah"


try


cout%26gt;%26gt; "blah blah


but i dont know much about c++


C++ programing to compute e^(x) and sin(x)?

for this program i'm required to use function...so here is what i have so far...





#include "stdafx.h"


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;math.h%26gt;


#include %26lt;string%26gt;


#include "stdlib.h"


using namespace System;


using namespace std;





double EtoX(double, double, int%26amp;);


double SineX(int x, int n);


_int64 Sentinel( );





int main()


{


int n;


double e, sin, ecx, exs;


switch





cout%26lt;%26lt;"enter the value of x, and epsilon"%26lt;%26lt;endl;


cin%26gt;%26gt;x%26gt;%26gt;eps%26gt;%26gt;;


e=EtoX(j);


sin=SineX(g);


cout%26lt;%26lt;"the value of e(x) is= "%26lt;%26lt;setprecision(15)%26lt;%26lt;j%26lt;%26lt;endl;


cout%26lt;%26lt;"the value of sine(x) is= "%26lt;%26lt;setprecision(15)%26lt;%26lt;g%26lt;%26lt;endl;





}





double EtoX(double x, double e, int n)





for(i=0; i%26lt;=n; ++i)


{


e= pow(n,i)/i;








i will greatly appreaciate it if someone can show me how to complete this..cause i'm stuck.

C++ programing to compute e^(x) and sin(x)?
I suppose that what you're trying to do is use the power series for exp(x) by summing up the terms x^n/n! until the next term is less than epsilon, right?





double EtoX(double x, double eps)


{


int n = 0;


denom = 1;


double sum = 1;


double increment = 1;


{


n += 1;


denom *= n;


increment *= x;


sum += increment/denom;


} while ( increment %26gt; eps );


return sum;


}





However, you should put a counter in there so that you'll exit if some dummy puts in eps=0 to avoid an infinite loop.
Reply:If what you intend to do is e^x and sin(x), math.h library has the "exp" and "sin" functions that will do it for you. The usage is something like:


exp(x) //where x is a double or float variable


sin(x) //where x is a double or float variable in radians.
Reply:should be:





math.e^ * x


math.sin * x


C++ Bank Program?

#include "Account.hpp"





Account::Account()


{





}











Account::Account(int *nstr)





{








int j = 1;





int withdrawMoney ,depositMoney;








cout %26lt;%26lt; "\n\n**** press 1 to withdraw money ****\n " ;





cout %26lt;%26lt; "\n**** press 2 to deposit money ****\n " ;





cout %26lt;%26lt; "\n**** press 0 to exit and return to main menu ****\n " ;





cout %26lt;%26lt; "\n Please, select your option : " ;





cin %26gt;%26gt; j;





switch(j)





{





case 1: cout %26lt;%26lt; "Enter the ammount to withdraw : ";





cin%26gt;%26gt; withdrawMoney;





nstr[0] -=withdrawMoney;





cout %26lt;%26lt; "\n your bank balance is now "





%26lt;%26lt;nstr[0] %26lt;%26lt; endl;break;








case 2: cout %26lt;%26lt; "Enter the ammount to deposit in account : ";





cin%26gt;%26gt; depositMoney;





nstr[0] += depositMoney;





cout %26lt;%26lt; "\n your bank balance is now "





%26lt;%26lt; nstr[0] %26lt;%26lt; endl;break;





case 0: cout %26lt;%26lt; " End of program. Thank you." %26lt;%26lt; endl;break;

C++ Bank Program?
Looks like a programming textbook example of an ATM user interface. It's not sufficiently comprehensive to use in real life, but it shows the outline structure of the code such that a trainee programmer could see what's going on. (However I'm a Forth programmer not C++, so I'm open to correction)
Reply:Looks like a menu


C++ prgm, input?

The following code is supposed to accept input that is between 1 %26amp; 5, %26amp; nonduplicaticates but it wont ask the input again if it's a duplicate. What's wrong? thanks!


do{


cout%26lt;%26lt;"Choose the first peg";


cin%26gt;%26gt;pegone;


cout%26lt;%26lt;endl;


if ( pegone %26lt; 1 || pegone %26gt; 5)


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while(pegone %26lt; 0 || pegone %26gt; 5);


do{


cout%26lt;%26lt;"Choose the second peg";


cin%26gt;%26gt;pegtwo;


cout%26lt;%26lt;endl;


if (( pegtwo %26lt; 1 || pegtwo %26gt; 5) || (pegtwo == pegone))


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while((pegtwo != pegone) %26amp;%26amp; ((pegtwo %26lt; 0) || (pegtwo %26gt; 5)));


do{


cout%26lt;%26lt;"Choose the third peg";


cin%26gt;%26gt;pegthree;


cout%26lt;%26lt;endl;


if (( pegthree %26lt; 1 || pegthree %26gt; 5) || ((pegthree == pegone) || (pegthree == pegtwo)))


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while(((pegthree != pegone) || (pegthree != pegtwo)) %26amp;%26amp; (pegthree %26lt; 0 || pegthree %26gt; 5));


}

C++ prgm, input?
Here is your correct program:


do{


cout%26lt;%26lt;"Choose the first peg";


cin%26gt;%26gt;pegone;


cout%26lt;%26lt;endl;


if ( pegone %26lt; 1 || pegone %26gt; 5)


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while(pegone %26lt; 1 || pegone %26gt; 5);


do{


cout%26lt;%26lt;"Choose the second peg";


cin%26gt;%26gt;pegtwo;


cout%26lt;%26lt;endl;


if (( pegtwo %26lt; 1 || pegtwo %26gt; 5) || (pegtwo == pegone))


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while((pegtwo == pegone) || ((pegtwo %26lt; 1) || (pegtwo %26gt; 5)));


do{


cout%26lt;%26lt;"Choose the third peg";


cin%26gt;%26gt;pegthree;


cout%26lt;%26lt;endl;


if (( pegthree %26lt; 1 || pegthree %26gt; 5) || ((pegthree == pegone) || (pegthree == pegtwo)))


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while(((pegthree == pegone) || (pegthree == pegtwo)) || (pegthree %26lt; 0 || pegthree %26gt; 5));
Reply:Don't Trust cardo's answer. It's a copy from Rag's answer
Reply:the while is in the wrong place.


for the second and third do while statements, do not use (not equal to) use (equal to)


remember, anything whithin the while statement that ends up to be true, will cause the do to be re-executed. also say || so either one will make it repeat.


while((pegtwo != pegone) %26amp;%26amp; (pegtwo %26lt; 0 || pegtwo %26gt; 5));


use


while((pegtwo == pegone) || (pegtwo %26lt; 0 || pegtwo %26gt; 5));


you have too many braces so I have removed some.


hope it works! see edited code below.contact me if you still have problems.





do{


cout%26lt;%26lt;"Choose the first peg";


cin%26gt;%26gt;pegone;


cout%26lt;%26lt;endl;


if ( pegone %26lt; 1 || pegone %26gt; 5)


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while(pegone %26lt; 1 || pegone %26gt; 5);





do{


cout%26lt;%26lt;"Choose the second peg";


cin%26gt;%26gt;pegtwo;


cout%26lt;%26lt;endl;


if (( pegtwo %26lt; 1 || pegtwo %26gt; 5) || (pegtwo == pegone))


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while((pegtwo == pegone) || (pegtwo %26lt; 0 || pegtwo %26gt; 5));





do{


cout%26lt;%26lt;"Choose the third peg";


cin%26gt;%26gt;pegthree;


cout%26lt;%26lt;endl;


if (( pegthree %26lt; 1 || pegthree %26gt; 5) || (pegthree == pegone || pegthree == pegtwo))


cout%26lt;%26lt;"Please select a number from 1 to 5 or do not chose a duplicate "%26lt;%26lt;endl;


} while(((pegthree == pegone) || (pegthree == pegtwo)) || (pegthree %26lt; 0 || pegthree %26gt; 5));


}

kudzu

C++ help program is written just need some help with the loop?

int main ( )


{





InputData();


while(CostOfPurchase != -1)


{


CHANGE();





OutputData();


}


return 0;


}








void InputData()


{


cout%26lt;%26lt;"Enter cost of purchase : ";


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl%26lt;%26lt;endl;








cout%26lt;%26lt;"Enter amount tendered : ";


cin%26gt;%26gt; AmountTendered;


cout%26lt;%26lt;endl%26lt;%26lt;endl;








}








void CHANGE()


{


FinalChange= AmountTendered - CostOfPurchase;





(int)dollar= (FinalChange + 0.00001)/1.00;


change = (FinalChange + 0.00001) - dollar;





(int)quarter= change/0.25;


change = change - .25*quarter;





(int)nickel= change/0.05;


change = change - .05 * nickel;





(int)penny = change/0.01;





}





void OutputData()


{





cout%26lt;%26lt; fixed%26lt;%26lt;showpoint%26lt;%26lt;setprecision(2);





cout%26lt;%26lt;"The change is $"%26lt;%26lt; FinalChange %26lt;%26lt;endl;





cout%26lt;%26lt; dollar%26lt;%26lt;" dollar"%26lt;%26lt;endl;


cout%26lt;%26lt; quarter%26lt;%26lt;" quarter"%26lt;%26lt;endl;


cout%26lt;%26lt; nickel%26lt;%26lt; " nickel"%26lt;%26lt;endl;


cout%26lt;%26lt; penny%26lt;%26lt; " penny" %26lt;%26lt;endl%26lt;%26lt;endl;





}

C++ help program is written just need some help with the loop?
You need to enter it in InputData() just before the first line. So it should look like this:





void InputData()


{


while (CostOfPurchase != -1)


{


cout%26lt;%26lt;"Enter cost of purchase : ";


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl%26lt;%26lt;endl;


}





cout%26lt;%26lt;"Enter amount tendered : ";


cin%26gt;%26gt; AmountTendered;


cout%26lt;%26lt;endl%26lt;%26lt;endl;








}





At least that's what it seems like your asking





Bet of Luck!
Reply:I understand what you are saying....





You are using a sentinel value -1, to end the input, ie to know when the user is done. A sentinel value is a value, that would not make sense to be the input of the cost of a purchase of a -1, so the loop is intended to make your program run until a -1 has been entered








so it would go at the very begging of your main function








do this








int main(){





//double or int what ever type you are using for cost of purchase i'm gonna use double


// declare costofpurcahse


// with a value that satisfies the condition of the loop


// to sort of trick it into running the loop


double costofpurchase = 0;





while(costofpurchase != -1){





// the data is inputed and costofpurchase is assigned a new value


inputData();





// cost of purchase will be entered over and over


// until the user is done and enters -1


// and your program runs everytime





// add if statement so if the user is done and cost of


// purchase == -1 there is no output so surround the call to your OutputData()


// with





if(costofpurchase != -1){


outputdata()


}





/*


code for your program





*/





// end of loop you were asking about


};





return 0;


};








for your case this is the answer





int main ( )


{





double costofpurchase = 0;





while(costofpurchase != -1){


InputData();





// if it is -1 the user doesn't want to know the change


// because that means they are done


if(costofpurchase != -1){


CHANGE();








OutputData();


};








};//end of loop


return 0;


}








hope that helps


Someone pleeeeeeeeeease finish this calendar program in c++?

if (month==1){


cout%26lt;%26lt;"\t\tJanuary"%26lt;%26lt;endl;


numdays=31;


}


else if (month==2){


cout%26lt;%26lt;"\t\tFebuary"%26lt;%26lt;endl;


numdays=28;


}


else if (month==3){


cout%26lt;%26lt;"\t\tMarch"%26lt;%26lt;endl;


numdays=31;


}


else if (month==4){


cout%26lt;%26lt;"\t\tApril"%26lt;%26lt;endl;


numdays=30;


}//end else if


else if (month==5){


cout%26lt;%26lt;"\t\tMay"%26lt;%26lt;endl;


numdays=31;


}


else if (month==6){


cout%26lt;%26lt;"\t\tJune"%26lt;%26lt;endl;


numdays=30;


}


else if (month==7){


cout%26lt;%26lt;"\t\tJuly"%26lt;%26lt;endl;


numdays=31;


}


else if (month==8){


cout%26lt;%26lt;"\t\tAugust"%26lt;%26lt;endl;


numdays=31;


}


else if (month==9){


cout%26lt;%26lt;"\t\tSeptember"%26lt;%26lt;endl;


numdays=30;


}


else if (month==10){


cout%26lt;%26lt;"\t\tOctober"%26lt;%26lt;endl;


numdays=31;





}


else if (month==11){


cout%26lt;%26lt;"\t\tNovember"%26lt;%26lt;endl;


numdays=30;


}else if (month==12){


cout%26lt;%26lt;"\t\tDecember"%26lt;%26lt;endl;


numdays=31;


}


cout%26lt;%26lt;"\tS M T W T F S"%26lt;%26lt;endl;


cout%26lt;%26lt;"-----------------------...





cout.setf(ios::right);


cout.width((days+5)*(days=4));


cout%26lt;%26lt;"1";


days++;


for(int num=2; num%26lt;=numday

Someone pleeeeeeeeeease finish this calendar program in c++?
if (month==1){


cout%26lt;%26lt;"\t\tJanuary"%26lt;%26lt;endl;


numdays=31;


}


else if (month==2){


cout%26lt;%26lt;"\t\tFebuary"%26lt;%26lt;endl;


numdays=28;


}


else if (month==3){


cout%26lt;%26lt;"\t\tMarch"%26lt;%26lt;endl;


numdays=31;


}


else if (month==4){


cout%26lt;%26lt;"\t\tApril"%26lt;%26lt;endl;


numdays=30;


}//end else if


else if (month==5){


cout%26lt;%26lt;"\t\tMay"%26lt;%26lt;endl;


numdays=31;


}


else if (month==6){


cout%26lt;%26lt;"\t\tJune"%26lt;%26lt;endl;


numdays=30;


}


else if (month==7){


cout%26lt;%26lt;"\t\tJuly"%26lt;%26lt;endl;


numdays=31;


}


else if (month==8){


cout%26lt;%26lt;"\t\tAugust"%26lt;%26lt;endl;


numdays=31;


}


else if (month==9){


cout%26lt;%26lt;"\t\tSeptember"%26lt;%26lt;endl;


numdays=30;


}


else if (month==10){


cout%26lt;%26lt;"\t\tOctober"%26lt;%26lt;endl;


numdays=31;





}


else if (month==11){


cout%26lt;%26lt;"\t\tNovember"%26lt;%26lt;endl;


numdays=30;


}else if (month==12){


cout%26lt;%26lt;"\t\tDecember"%26lt;%26lt;endl;


numdays=31;


}


cout%26lt;%26lt;"\tS M T W T F S"%26lt;%26lt;endl;


cout%26lt;%26lt;"-----------------------...





cout.setf(ios::right);


cout.width((days+5)*(days=4));


cout%26lt;%26lt;"1";


days++;


for(int num=2; num%26lt;=numday


day9jhgdheyyy


ekjreijt


64949rrmkfkj59,k


C++ question, I know someone out there knows?

int main ( )


{





InputData();


while(CostOfPurchase != -1)


{


CHANGE();





OutputData();


}


return 0;


}








void InputData()


{


cout%26lt;%26lt;"Enter cost of purchase : ";


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl%26lt;%26lt;endl;








cout%26lt;%26lt;"Enter amount tendered : ";


cin%26gt;%26gt; AmountTendered;


cout%26lt;%26lt;endl%26lt;%26lt;endl;








}








void CHANGE()


{


FinalChange= AmountTendered - CostOfPurchase;





(int)dollar= (FinalChange + 0.00001)/1.00;


change = (FinalChange + 0.00001) - dollar;





(int)quarter= change/0.25;


change = change - .25*quarter;





(int)nickel= change/0.05;


change = change - .05 * nickel;





(int)penny = change/0.01;





}





void OutputData()


{





cout%26lt;%26lt; fixed%26lt;%26lt;showpoint%26lt;%26lt;setprecision...





cout%26lt;%26lt;"The change is $"%26lt;%26lt; FinalChange %26lt;%26lt;endl;





cout%26lt;%26lt; dollar%26lt;%26lt;" dollar"%26lt;%26lt;endl;


cout%26lt;%26lt; quarter%26lt;%26lt;" quarter"%26lt;%26lt;endl;


cout%26lt;%26lt; nickel%26lt;%26lt; " nickel"%26lt;%26lt;endl;


cout%26lt;%26lt; penny%26lt;%26lt; " penny" %26lt;%26lt;endl%26lt;%26lt;endl;





}

C++ question, I know someone out there knows?
like i said earlier you must declare cost of purchase with a value so the loop is entered then you input data in the loop








int main ( )


{





double CostOfPurcase = 0;


//YOU HAVE TO DECLARE THIS VARIABLE HERE AND IT HAS TO BE = 0. TAKE ALL OTHER DECLARATIONS OUT EXCEPT THIS ONE!!!





while(CostOfPurchase != -1)


{





inputData();


CHANGE();





OutputData();


}


return 0;


}








void InputData()


{


cout%26lt;%26lt;"Enter cost of purchase : ";


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl%26lt;%26lt;endl;








cout%26lt;%26lt;"Enter amount tendered : ";


cin%26gt;%26gt; AmountTendered;


cout%26lt;%26lt;endl%26lt;%26lt;endl;








}








if you are still doing











#include%26lt;iostream%26gt;


#include%26lt;iomanip%26gt;


using namespace std;








int dollar, quarter, nickel,penny;


double CostOfPurchase, AmountTendered, change, CHANGE;





int main ( )


{


cout%26lt;%26lt;"Enter cost of Purchase: "%26lt;%26lt;endl;


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter amount tendered: "%26lt;%26lt;endl;


cin%26gt;%26gt; AmountTendered;


cout%26lt;%26lt;endl;











that is WRONG DECLARE COST OFPURCAHSE IN YOUR MAIN FUNCTION WITH A VALUE THAT IS NOT == to -1 so the loop is entered and input can take place
Reply:i use the exit(); command to just end the programs, however im using the customized compiler of C++ so im not sure if yours is the same... it shold be. in the while loop add if(answer == -1) exit();
Reply:so umm what's your question exactly?





int main ( )


{





while(CostOfPurchase != -1)


{


InputData();


}


return 0;


}





void InputData()


{


cout%26lt;%26lt;"Enter cost of purchase : ";


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl%26lt;%26lt;endl;





if(CostOfPurchase!=-1)


{


cout%26lt;%26lt;"Enter amount tendered : ";


cin%26gt;%26gt; AmountTendered;


cout%26lt;%26lt;endl%26lt;%26lt;endl;


CHANGE();


OutputData();


}





}





PS I'm assuming CostOfPurchase is a "global" variable, bad practice btw.
Reply:It needs to be in the InputData function:





cout%26lt;%26lt;"Enter cost of purchase : ";


cin%26gt;%26gt; CostOfPurchase;





RIGHT HERE





cout%26lt;%26lt;endl%26lt;%26lt;endl;





---------------------------------


Put an if statement RIGHT HERE, checking the value of CostOfPurchase. If it equals -1, then exit the program.
Reply:No they don't, because you forgot to ask the question.
Reply:it is saying that you are going to be a math person or something to do with money...like a bank...you are counting change, and you end up with a "dollar" "quarter" "nickle" "penny" so youreally end up with $1.31 all together...CORRECT?? probably not...oh well im bored..hah
Reply:Maybe this:





int main ( )


{





InputData();


while(CostOfPurchase != -1)


{


CHANGE();





OutputData();





InputData(); //I just added this


}


return 0;


}
Reply:I answered this question a few minutes ago, reposting is frowned upon, you should have editted your first question. I will put my answer here along with the additional question you have to answer.





You need to enter it in InputData() just before the first line. Also to break out of the void function without entering Amount Tendered, you need a return statement. So it should look like this:





void InputData()


{


while (CostOfPurchase != -1)


{


cout%26lt;%26lt;"Enter cost of purchase : ";


cin%26gt;%26gt; CostOfPurchase;


cout%26lt;%26lt;endl%26lt;%26lt;endl;


}





return;





}








You will have to create a separate function for getting Amount Tendered or else it will never reach there.





At least that's what it seems like your asking





Bet of Luck!
Reply:you're wrong, we don't know unless you actually ask us a question - you simply said 'I know someone out there knows?' then pasted a bunch of source code.





we don't possess psychic abilities so unless you explain what the question is you're not going to have any luck.





are you trying to say there's an error in the code? you don't know what the code does? how the code could be improved? what?
Reply:Are you declaring the functions in a header file before you use them? If not either make a header file, or put the functions before the main function, so that main is last. This way the compiler can find them before the main function calls them.