Sunday, August 2, 2009

HeLP WITH MY C++ PROGRAMMING?

This is what I have (the do...while loop won't run):





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


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


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





void main()


{


char namelast[81], namefirst[81];


int count=0;





cout%26lt;%26lt;"Please enter your last name: "%26lt;%26lt;endl;


cin.get (namelast, 81);


cout%26lt;%26lt;"Please enter your first name: "%26lt;%26lt;endl;


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


cin.get (namefirst, 81);


cout%26lt;%26lt;"Based on the given information, your name is "%26lt;%26lt;namefirst%26lt;%26lt;" "%26lt;%26lt;namelast%26lt;%26lt;"."%26lt;%26lt;endl;





if(namelast=="Lee")


{


cout%26lt;%26lt;"You an AzN !"%26lt;%26lt;endl;


}


if(namelast=="Lee" %26amp;%26amp; namefirst=="Kyle")


{


do{ cout%26lt;%26lt;"YOU'RE A DOUCHE! "%26lt;%26lt;endl;


count=count++;


}while(getch());


cout%26lt;%26lt;"You just got owned "%26lt;%26lt;count%26lt;%26lt;" times, Kyle Lee! What now, DOUCHE?!"%26lt;%26lt;endl;


}


getch();


}

HeLP WITH MY C++ PROGRAMMING?
You need to do a string compare:





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


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


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





int main()


{


char namelast[81], namefirst[81];


int count=0;





cout%26lt;%26lt;"Please enter your last name: "%26lt;%26lt;endl;


cin.get (namelast, 81);


cout%26lt;%26lt;"Please enter your first name: "%26lt;%26lt;endl;


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


cin.get (namefirst, 81);


cout%26lt;%26lt;"Based on the given information, your name is "%26lt;%26lt;namefirst%26lt;%26lt;" "%26lt;%26lt;namelast%26lt;%26lt;"."%26lt;%26lt;endl;





if(!strcmp(namelast,"Lee"))


{


cout%26lt;%26lt;"You an AzN !"%26lt;%26lt;endl;


}


if(!strcmp(namelast,"Lee") %26amp;%26amp; !strcmp(namefirst,"Kyle"))


{


do{ cout%26lt;%26lt;"YOU'RE A DOUCHE! "%26lt;%26lt;endl;


count=count++;


}while(getch());


cout%26lt;%26lt;"You just got owned "%26lt;%26lt;count%26lt;%26lt;" times, Kyle Lee! What now, DOUCHE?!"%26lt;%26lt;endl;


}


getch();


}





String compare will return 0 if the strings match.
Reply:I don't like this program...anyway, what is with the getch()? Also, count++ increments count, you don't have to assign count to it.





count++ is the same as saying count = count++


Easy Basic C++ Programming Help?

Doing a while loop that will allow the user to continue running the program until they enter 'x' to exit the program. It keeps giving me previous results added onto when you run it again. How do u make the program start over the results the 2nd time around?





int counter = 0;


int oddcount = 0;


int num1;


int scores;


char letter;


int highestscore = 0;








while (letter != 'x')





{


cout%26lt;%26lt;"How many scores are you entering?"%26lt;%26lt;endl;


cin%26gt;%26gt;num1;








for (int counter=0; counter%26lt;num1;counter++)


{





cout%26lt;%26lt;"Enter an integer: "; cin%26gt;%26gt;scores;





cout%26lt;%26lt;endl;








oddcount += (( scores % 2)!= 0);





if ( scores %26gt; highestscore )





highestscore = scores;


}


cout%26lt;%26lt;"You entered "%26lt;%26lt;oddcount%26lt;%26lt;" odd numbers."%26lt;%26lt;endl;


cout%26lt;%26lt;"The highest # is "%26lt;%26lt;highestscore%26lt;%26lt;endl;


cout%26lt;%26lt;"Finish...press 'x' to exit program. any other key to run again."%26lt;%26lt;endl;


cin%26gt;%26gt;letter;


}

Easy Basic C++ Programming Help?
Do this when you enter the while loop:


oddcount = highestscore = 0;





By the way, you're using the variable 'letter' before you set it. This is generally a bad idea. Always set data before you use it. You may want to change your loop to a do { } while, so letter will only be checked after the cin.
Reply:I've been tracking your problem as you continually post the same question. First off, the person on the previous question is wrong. Unless I'm mistaken, you're trying to count how many odd numbers have been entered? The += operator basically is doing this: oddcount = oddcount + scores%2. In the code, that's not even syntaxually correct. It should actually be this:





(keep in mind, this is still in the "for" loop)





if ((scores % 2) != 0)


{


oddcount++;


{





%26lt;rest of code here%26gt;





Also, you should initialize your INSIDE the while loop. Otherwise, if the person doesn't press x, the values stored in the variables are still the same (because only the stuff inside the while loop is run again). Put all your initializations of your variables as the first thing in the while loop. Because once the loop starts over, it'll reinitialize the variables again and clear all previous data (meaning you won't get the same answers). Also, initialize num1 and scores to 0 so that they reset themselves too.

forsythia

C ++ help please!?

this program should calculate the overtime (if any) and the gross pay.





it just showing me the gross pay in both, the gross output and overtime output. what am i doing wrong? please help me!


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


double hours = 0.0;


double rate = 0.0;


double gross = 0.0;


double overtime = 0.0;





//enter input


cout %26lt;%26lt; "Enter the hours worked: ";


cin %26gt;%26gt; hours;


cout %26lt;%26lt; "Enter the pay rate: ";


cin %26gt;%26gt; rate;





//calculate overtime pay and gross pay


if (hours %26gt; 40.0 || hours %26lt;= 40.0)


{


overtime = (hours * rate) + overtime;


gross = hours *rate;


} //end if


//display output


cout %26lt;%26lt; "Overtime: " %26lt;%26lt; overtime %26lt;%26lt; endl;


cout %26lt;%26lt; "Gross pay: " %26lt;%26lt; gross %26lt;%26lt; endl;


return 0;


} //end of main function

C ++ help please!?
Your if statement is wrong. It lets everything fall through.
Reply:if (hours %26gt; 40.0 || hours %26lt;= 40.0)


{


overtime = (hours * rate) + overtime;


gross = hours *rate;


} //end if





This condition is always met.





In +overtime, overtime is always 0.0.
Reply:I think your problem is in this line:


overtime = (hours * rate) + overtime;





it should be something like:





overtime = (hours - 40) * rate;


C ++ help please!?

this program should calculate the overtime (if any) and the gross pay.





it just showing me the gross pay in both, the gross output and overtime output. what am i doing wrong? please help me!


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


double hours = 0.0;


double rate = 0.0;


double gross = 0.0;


double overtime = 0.0;





//enter input


cout %26lt;%26lt; "Enter the hours worked: ";


cin %26gt;%26gt; hours;


cout %26lt;%26lt; "Enter the pay rate: ";


cin %26gt;%26gt; rate;





//calculate overtime pay and gross pay


if (hours %26gt; 40.0 || hours %26lt;= 40.0)


{


overtime = (hours * rate) + overtime;


gross = hours *rate;


} //end if


//display output


cout %26lt;%26lt; "Overtime: " %26lt;%26lt; overtime %26lt;%26lt; endl;


cout %26lt;%26lt; "Gross pay: " %26lt;%26lt; gross %26lt;%26lt; endl;


return 0;


} //end of main function

C ++ help please!?
Your if statement is wrong. It lets everything fall through.
Reply:I think your problem is in this line:


overtime = (hours * rate) + overtime;





it should be something like:





overtime = (hours - 40) * rate;
Reply:if (hours %26gt; 40.0 || hours %26lt;= 40.0)


{


overtime = (hours * rate) + overtime;


gross = hours *rate;


} //end if





This condition is always met.





In +overtime, overtime is always 0.0.


C++ Help Please!?

Hello, I am trying to run this class, but when I compile, it is telling me that "cout" and "endl" are undeclared integers....? I obviously just want the results to be output, but what do I have to do to fix this? Any help is appreciated.





class Rectangle


{


public:


Rectangle()


{


height= 0;


width = 0;


}





Rectangle(double h, double w)


{


height = h;


width = w;


}





double getHeight() // retrive the height to print in main


{


return height;


}





double getWidth() // retrive the width to print in main


{


return width;


}





double getArea()const


{


return height * width;


}





double getPerimeter()


{


return ((height * 2) + (width * 2));


}





private:


double height;


double width;


};





int main()


{


Rectangle rectangle1(5,50);


Rectangle rectangle2(3.5,35.9);





cout %26lt;%26lt; rectangle1.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle1.getPerimeter() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle2.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle2.getPerimeter() %26lt;%26lt; endl;





return 0;


}

C++ Help Please!?
Just add the following two lines at the start





#include %26lt;iostream%26gt;


using namespace std;
Reply:#include %26lt;iostream%26gt;


using std::cout;


using std::endl;








or, just


#include %26lt;iostream%26gt;


//and you have to use the namespace in your code.





std::cout%26lt;%26lt; blah %26lt;%26lt; cout::endl;


Help me with a c++ program please?

hey i need a little help with a program, ill post part of the program and then ask my question





#include%26lt;iostream%26gt;


#include%26lt;string%26gt;


#include%26lt;fstream%26gt;





using namespace std;





class Course{


string name;


char grade;


int hours;


public:


string ("") in the default constructor.


Course(){


name = "";


grade = "";


hours = 0;


}


Course(string n, char g, int h);





void setName(string n){name=n};


void setGrade(char g){grade=g};


void setHours(int h){hours=h};





string getName(){return name};


char getGrade(){return grade};


int getHours(){return hours};





void print(){


if (name != ""){


cout.width(10); cout%26lt;%26lt; name;


cout.width(4); cout %26lt;%26lt; grade;


cout.width(4); cout %26lt;%26lt; hours %26lt;%26lt; endl;


}


else


cout %26lt;%26lt; "....." %26lt;%26lt; endl;


}


};


class Student{


string last,first,street,city,state,zip,major,m...


int id;


int num_classes;


Course classes[15];


int hours_att, hours_earned, grade_points;


double gpa;

Help me with a c++ program please?
can you tell me what happens when you run it

jasmine

I have a problem with this program in C++ on Stacks?I get Error: Directive:Must Use C++ for Type IOSTREAM.I'

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


class ArrStack


{


int Top_of_stack;


char *Stack;


int size;


public:


ArrStack(int s=10);


~ArrStack(){delete[] Stack;}


void Push(char ch);


void Pop(void);


void Top_nopop(void);


void Top_Pop(void);


void gettop(void);


void Empty_S(void);


int Is_Empty()


{return Top_of_Stack==-1;}


int Is_Full()


{return Top_of_Stack==size-1;}


};


ArrStack::ArrStack(int s)


{size=s;


Stack=new char[size];


Top_of_stack=-1;


}


void ArrStack::Push(char ch)


{


if(Is_Full())


{cout%26lt;%26lt;"Sorry!Stack Full"%26lt;%26lt;endl;


}


else


{


Stack[++Top_of_stack]=ch;}


}


void ArrStack::Pop()


{


if(Is_Empty())


{cout%26lt;%26lt;"Sorry!Stack Empty"%26lt;%26lt;endl;


}


else{


--Top_of_Stack;}


}


void ArrStack::Top_nopop()


{


if(Is_Empty())


{cout%26lt;%26lt;"Sorry!Stack Empty"%26lt;%26lt;endl;}


else{


cout%26lt;%26lt;Stack[Top_of_stack];}


}}


void ArrStack::Top_Pop()


{


if(Is_Empty())


{cout%26lt;%26lt;"Sorry!Stack Empty"%26lt;%26lt;endl;}


else


{


cout%26lt;%26lt;Stack[Top_of_stack];


--Top_of_stack;}


}


void ArrStack::gettop()


{


cout%26lt;%26lt;Top_of_stack;


}


void Empty_S()





{


Top_of_stack=-1;


}

I have a problem with this program in C++ on Stacks?I get Error: Directive:Must Use C++ for Type IOSTREAM.I'
Your problem is that your compiler thinks this is a C file. Either your compiler or your IDE. Without knowing what compiler you are using (though I'd guess Turbo C++ or Borland C++) I'd say first, make sure the file name ends in .cpp, not .c. If it ends in .c then you are going to get the same error. Don't change the name, though, to be safe copy it into a cpp file you should then try to compile. If that doesn't work follow the instructions for compiling it from the command line (tcc %26lt;filename%26gt;.cpp or whatever).





If that doesn't work we need to know what compiler you're using specifically.





Okay, given the new information, I've cleaned this up a little and added the new syntax (since the heyday of Turbo C the header files have changed and I'm using GCC on Linux. This compiles without too many problems. The biggest change was putting ArrStack:: in front of Empty_S(). There are a few syntax errors here and there to run:





#include%26lt;iostream%26gt;





using namespace std;





class ArrStack


{


int Top_of_stack;


char *Stack;


int size;


public:


ArrStack(int s=10);


~ArrStack(){delete[] Stack;}


void Push(char ch);


void Pop(void);


void Top_nopop(void);


void Top_Pop(void);


void gettop(void);


void Empty_S(void);


int Is_Empty()


{return Top_of_stack==-1;}


int Is_Full()


{return Top_of_stack==size-1;}


};


ArrStack::ArrStack(int s)


{size=s;


Stack=new char[size];


Top_of_stack=-1;


}


void ArrStack::Push(char ch)


{


if(Is_Full())


{cout%26lt;%26lt;"Sorry!Stack Full"%26lt;%26lt;endl;


}


else


{


Stack[++Top_of_stack]=ch;}


}


void ArrStack::Pop()


{


if(Is_Empty())


{cout%26lt;%26lt;"Sorry!Stack Empty"%26lt;%26lt;endl;


}


else{


--Top_of_stack;}


}


void ArrStack::Top_nopop()


{


if(Is_Empty())


{cout%26lt;%26lt;"Sorry!Stack Empty"%26lt;%26lt;endl;}


else{


cout%26lt;%26lt;Stack[Top_of_stack];}


}


void ArrStack::Top_Pop()


{


if(Is_Empty())


{cout%26lt;%26lt;"Sorry!Stack Empty"%26lt;%26lt;endl;}


else


{


cout%26lt;%26lt;Stack[Top_of_stack];


--Top_of_stack;}


}


void ArrStack::gettop()


{


cout%26lt;%26lt;Top_of_stack;


}


void ArrStack::Empty_S()





{


Top_of_stack=-1;


}





Header files tend to begin:





#ifndef %26lt;Token of the header file%26gt;


#define %26lt;Token of the header file%26gt;





Then at the very end of the file is:


#endif





That is so if it is called twice the compiler doesn't get confused and compile it twice. In C it would return an error though with overloading I don't know what C++ would do. If this header file is called by a CPP program try saving it as an hpp. If it's not called by a CPP program (which itself includes iostream.h) then you have a problem right there. Make sure it's #included into a C++ program.


C++ help please! why my program wont show up my output with 2 decimals?

i have included the #include %26lt;iomanip%26gt;, using std::fixed;


and using std::setprecision; still it wont show up my output with the 2 decimals. why? 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


char seatLocation = ' ';


int ticketPrice = 0;





//enter input


cout %26lt;%26lt; "Enter seat location (B(box), P(pavilion), or L(Lawn): ";


cin %26gt;%26gt; seatLocation;


seatLocation = toupper(seatLocation);





//calculate and display order price





switch (seatLocation)


{


case 'B':


ticketPrice = 75;


break;


case 'P':


ticketPrice = 30;


break;


case 'L':


ticketPrice = 21;


break;


default:


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


}


//end switch





// display shipping charge


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


cout %26lt;%26lt; "Ticket price: $" %26lt;%26lt; ticketPrice %26lt;%26lt; endl;


cin %26gt;%26gt; ticketPrice;


return 0;


} //en

C++ help please! why my program wont show up my output with 2 decimals?
If you're wondering why ticketPrice isn't showing 2 decimals, it's because you've declared it as an int. Int's do not have the capability to store decimal places, you need to use the datatype double.
Reply:Maybe because TicketPrice is an int and int's don't have decimal precisions. Try making it a double.





Hope that helps.


C++ problem?

i have to write a program that counts how many negative numbers the user enters. here is what i have so far:





void main()


{


cout %26lt;%26lt; "This program count how many negative numbers you enter. \nThere will be three sections. \nEnter 0 to end a section." %26lt;%26lt;endl%26lt;%26lt;endl;





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


{


cout %26lt;%26lt; "\n************ SECTION " %26lt;%26lt; i+1 %26lt;%26lt; "**************"%26lt;%26lt;endl;


cout %26lt;%26lt; "\nYou have entered " %26lt;%26lt; getInput() %26lt;%26lt; " negative numbers so far."%26lt;%26lt;endl;


cout %26lt;%26lt; "**************************"%26lt;%26lt;endl%26lt;%26lt;endl...





}





return;


}





int getInput()


{


double number; //hold number entered by the user


count=0;





//get input


do


{


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


cin %26gt;%26gt; number;





//count positive number


if (number %26lt; 0)


count ++;


} while (number !=0);





//return counting result


return count;





}





when i compile it, it says "getInput" indentifier not found and count not declared. i dun see what i'm doing wrong. thanks for the help

C++ problem?
May be you can post your requirements at http://expert.ccietutorial.com/


and let many programmers bid for your project.


You can hire whoever you like.





Do not pay any money afront however.
Reply:As the previous responder said, you need to declare your variable count in the getInput( ) function, i.e. :


int count = 0;





The other problem is you're calling getInput( ) from main( ), but getInput( ) hasn't been declared or defined yet. The definition of the function appears below main( ) in your code, which is fine, but you need to declare it before it's called. So, you need this line before the beginning of main( ):





int getInput(void);





One other minor thing: the comment in getInput( ) says you're counting positive numbers, but you're counting negatives.
Reply:Try :


int count = 0;


not


count=0;


C++.im supposed to display the initials of the names. but it doesnt work.what hav i done wrong..pls help!?

#include%26lt;iostream%26gt;





using namespace std;





int main()


{


char firstinitial, middleinitial, lastinitial;





cout%26lt;%26lt;"please enter your first name:"%26lt;%26lt;endl;


cin.get(firstinitial);


cin.ignore(100, ' ');


cout%26lt;%26lt;"Please enter your middle name:"%26lt;%26lt;endl;


cin.get(middleinitial);


cin.ignore(100, ' ');


cout%26lt;%26lt;"please enter your last name:"%26lt;%26lt;endl;


cin.get(lastinitial);


cin.ignore(100, ' ');


cout%26lt;%26lt;"the initial of all three names are: ";


cout%26lt;%26lt;firstinitial%26lt;%26lt;middleinitial%26lt;%26lt;las...





return 0;


}

C++.im supposed to display the initials of the names. but it doesnt work.what hav i done wrong..pls help!?
Why are you using cin.ignore() ?

crab apple

C++ question?

this is what ive got too.


i need to be able to put a number in 1 through ten and then have the program convert it to a roman numeral.





direct me with code the right way. thanks





#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;





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


{


cout %26lt;%26lt; " *This program was written by Jacob A. DePratti*" %26lt;%26lt; endl;


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











cout %26lt;%26lt; "Please Enter A Number 1 Through Ten" %26lt;%26lt; %26lt;%26lt; endl;


cout %26lt;%26lt; "The Roman Numeral Of This Number Is: " %26lt;%26lt; %26lt;%26lt; endl;


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





system("PAUSE");


return EXIT_SUCCESS;


}

C++ question?
Use SWITCH:





char s[10];


switch(num)


{


case 1: strcpy(s,"I");


case 2: strcpy(s,"II");


case 3:


.....


case 10: strcpy(s, "X")


}





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


Programming help.. C++ Change making?

#include %26lt;iostream%26gt;


using namespace std;


int main()


{


int dollars,quarters,dimes,nickels,pennies,a...


cout %26lt;%26lt; "Please enter amount_due:";


cin %26gt;%26gt; amount_due;


amount_due_value = amount_due*100;


cout %26lt;%26lt; "Please enter the amount of money you intend to use:\n"


%26lt;%26lt; "Please enter the number of dollars:";


cin %26gt;%26gt; dollars;


dollar_value = dollars*100;


cout %26lt;%26lt; "Please enter the number of quarters";


cin %26gt;%26gt; quarters;


quarter_value = quarters*25;


cout %26lt;%26lt; "Please enter the number of dimes";


cin %26gt;%26gt; dimes;


dime_value = dimes*10;


cout %26lt;%26lt; "Please enter the number of nickels";


cin %26gt;%26gt; nickels;


nickel_value = nickels*5;


cout %26lt;%26lt; "Please enter the number of pennies";


cin %26gt;%26gt; pennies;


penny_value = pennies*1;


dollars_due = amount_due_value - dollar_value;


quarters_due = (amount_due_value-dollars_due)/quarter_v...

Programming help.. C++ Change making?
What's the problem? (You want us to compile this and debug it for you?)





***Update***


OK - I'm guessing at what it's supposed to do. I suspect you'll enter an amount due and an amount paid, like 33.58 (due) and 50.00 paid, and the program should spit out something like:


Change due: $16.42 paid as


1 Ten dollar bill,


1 Five dollar bill,


1 One dollar bill,


1 Quarter,


1 Dime,


1 Nickle,


2 pennies.





If this is correct, then you can do it using the following logic:





1) Get the amount due and amount paid (You alreadu have this as amount_due and dollars)


2) These should both be float values as you'll want to know fraction values.





3) Once you get the input, you need to validate it. Make sure the amount due is %26gt; 0.01 and that the amount paid is %26gt; amount due.





4) Create two arrays to hold your "change drawer" items. This would be something like:


char changeDesc[9][30] = {


"One Hundred Dollar Bill","Fifty Dollar Bill","Twenty Dollar Bill", %26lt;fill in the rest%26gt; %26lt;"Dime","Nickle","Pennies"};


float changeAmt[9]={10000,5000,2000, ... 10, 5, 1};


//Note: above values are 100* actual value to remove decimal.





5) Calculate the amount due: changeDue=(int)(dollars-amount_due*100);





7) You'll then have a loop which will compute a reducing balance based on the number of change items given.


Each time through, you'll compare the changeDue value to that in the changeAmt[position]. If it's smaller than the changeAmt[position] value, add one to position. If not, then print out 1 changeDesc[position] value andsubtract changeAmt[position] from the change_due.





Now the above will print multiple lines for each time. For example, if you should get three one dollar bills, it'll print One Dollar Bill three times. You can add code to total each item up and print the total, but get the first part working before you worry about that. Post a new question with your changed source once you're ready for review.





(Or - email me at mdr1119 @ sbcglobal.net and I'll respond.)
Reply:How come you are having the user enter the amount in each denomination?





The best approach would be to input the amount due first. Something like $5.25 instead of 5 dollars, 2 dimes and a nickel (which is what I am getting out of your program).





Once you have this total amount paid subtract that from the total amount due.





From there you will have change due. And then you can calculate the amount of change due as you currently are.





The only problem I see is that you never have a total of money used.
Reply:This is what i think ...





U have used integer variables in ur program right,


%26amp; u say u r getting modulo Errors;


so maybe if u r providing float values as input during the runtime it may be getting parsed into integers.


Easy Basic C++ Programming Help?

1) My odd counter won't work when I try to count the odd scores when I enter 39, 43, 62.


2) I'm trying to repeat the program when i press any letter except 'x'. when i do that, i get the same results as the first time around.





{





int counter = 0;


int oddcount = 0;


int num1;


int scores;


char letter;


int highestscore = 0;








while (letter != 'x')





{


cout%26lt;%26lt;"How many scores are you entering?"%26lt;%26lt;endl;


cin%26gt;%26gt;num1;





for (int counter=0; counter%26lt;num1;counter++)


{


{


cout%26lt;%26lt;"Enter an integer: "; cin%26gt;%26gt;scores;





cout%26lt;%26lt;endl;


}





oddcount = ( ( scores % 2) != 0);





oddcount++;





if ( scores %26gt; highestscore )





highestscore = scores;





}


cout%26lt;%26lt;"You entered "%26lt;%26lt;oddcount%26lt;%26lt;" odd numbers."%26lt;%26lt;endl;


cout%26lt;%26lt;"The highest # is "%26lt;%26lt;highestscore%26lt;%26lt;endl;


cout%26lt;%26lt;"Finish...press 'x' to exit program. any other key to run again."%26lt;%26lt;endl;


cin%26gt;%26gt;letter;


}

Easy Basic C++ Programming Help?
try setting oddcount and highestscore to 0 right after while (letter != 'x')





then replace





oddcount = ( ( scores % 2) != 0);


oddcount++;





with





oddcount += ((scores %2) != 0);





each time through the for loop oddcount is being reset to 0 or 1, and then incremented. So your answer output by oddcount will always be 1 or 2, even if you put in 100 odd numbers. The += adds the 0 or 1 to the previous value of oddcount.
Reply:Your code looks a bit incomplete? I'm guessing that there was another while statement at the top?





If you move the int declarations out of the outer while loop but still do the assignments inside that while loop it might work. I'm not sure of the theory but I have a feeling that the initialisations will only be done the first time if you declare the variables and assign to them at the same time.


What is " cout " undeclared?

i use a c++ compiler and i found this error or warning inside my source programme..... WhY?

What is " cout " undeclared?
#include%26lt;iostream.h%26gt;





put in the preprocessor


or seach if the header file IOSTREAM.H exists.

strawberry

In C++ I need to know what all of this code does every line documented and each loop specifically defined.help

#include %26lt;iostream%26gt;


using namespace std;





void main ()


{//begin main





//declare and initialize











int counter = 1;


int counter2 = 1;


int counter3 = 1;





//Process and Output








//For Loop: //test before





cout %26lt;%26lt; "The For loop output is:" %26lt;%26lt; endl;


for(counter = 1; counter %26lt;= 10; counter++)


{


cout %26lt;%26lt; "Loop counter is at " %26lt;%26lt; counter %26lt;%26lt; endl;


}





//While Do Loop: //test before





cout %26lt;%26lt; "The While Do loop(test before) output is:" %26lt;%26lt; endl;


while (counter2 %26lt;= 10)


{





cout %26lt;%26lt; "Loop counter2 is at " %26lt;%26lt; counter2 %26lt;%26lt; endl;


counter2 = counter2 +1;


}





//Do While loop: //test after








cout %26lt;%26lt; "The Do While(test after) loop output is:" %26lt;%26lt; endl;


do


{//begin loop





cout %26lt;%26lt; "Loop counter3 is at " %26lt;%26lt; counter3 %26lt;%26lt; endl;


counter3 = counter3 +1;





}//end loop


while (counter3 %26lt;= 10);





}//end main

In C++ I need to know what all of this code does every line documented and each loop specifically defined.help
lol!


Change C++ Program?

I need to write a program that will calucate how many quarters, dimes, nickels, and pennies a certain amount of cents will have. So for example, you enter 90 cents. That would be 3 quarters, 1 dime, 1 nickel, 0 pennies. I have this so far, im having trouble with the MATH part. The only thing working is the quarters.





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





main()


{


int quarters;


int dimes;


int nickels;


int pennies;


int number;





cout %26lt;%26lt; "Enter a number. " %26lt;%26lt; '\n';


cin %26gt;%26gt; number;





quarters = number / 25;


dimes = number - (quarters * 25) / 10;


nickels = number - (quarters * 25) / (dimes * 10) / 5;


pennies = number - (quarters * 25) / (dimes * 10) / (nickels * 5);





cout %26lt;%26lt; "Quarters - " %26lt;%26lt; quarters %26lt;%26lt; '\n';


cout %26lt;%26lt; "Dimes - " %26lt;%26lt; dimes %26lt;%26lt; '\n';


cout %26lt;%26lt; "Nickels - " %26lt;%26lt; nickels %26lt;%26lt; '\n';


cout %26lt;%26lt; "Pennies - " %26lt;%26lt; pennies %26lt;%26lt; '\n';


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


system("PAUSE");


return 0;


}

Change C++ Program?
OK, let's break this up a bit:





Quarters


-----------


Your calculation for quarters was fine.








Dimes


----------


You must not forget the order of operations for mathematical computations. Division happens before subtraction. Try something more like this:





dimes = (number - (quarters * 25)) / 10;








Nickels


----------


You should add together the number of cents present in the quarters and dimes before subtracting them from the number, like this:





nickels = (number - ((quarters * 25) + (dimes * 10)) / 5;








Pennies


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


For pennies, just subtract out the number of cents used in the quarters, dimes, and nickels.





pennies = number - ((quarters * 25) + (dimes * 10) + (nickels * 5));








That's my suggestion. Hope this helps. As an alternative, you could get the modula of the nickels calculation to get the pennies as well, like so:





pennies = (number - ((quarters * 25) + (dimes * 10)) % 5;


There is an error in my c++ program, help?

I cant find the errors on my program





these are my errors








: 'CarOrFight' : local function definitions are illegal


: end of file found before the left brace '{' at 'U:\game.cpp(171)' was matched












































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


int Gas();


int Gun();


int CarOrFight();





int main()


{


cout %26lt;%26lt;"Your an agent\n\n";


cout %26lt;%26lt; "The goverment sent you to investigate missing people in\nCosta Rico";


cout %26lt;%26lt; "\n\nYour in the woods, you see houses every half a mile\n\n";


cout %26lt;%26lt;"Your partner, Alex, tells you that you are running out of gas";


cout %26lt;%26lt;"You want to get to the town soon to investigate, but you are afraid you will run out of gas\n\n";


cout %26lt;%26lt;"You noticed that you just passed a gas station\n\n";


cout %26lt;%26lt;"You can turn back choice 1 \n";


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


cout %26lt;%26lt;"Get to town before gas runs out choice 2\n";


Gas();


return 0;


}

















int Gas()


{


enum Gas{turn=1,go};





int choice;


cin %26gt;%26gt; choice;


if (choice==turn)

There is an error in my c++ program, help?
We'll need the end of your code to help you...
Reply:Both errors are probably because you have a "{" (left brace) symbol but never put in the matching "}" (right brace) symbol, for example at the end of a function.





Go through your code and make sure every brace is in its place.
Reply:Your post looks to be incomplete or cutoff. Regardless, I can tell you what to look for. You most like forgot a semi-colon at end of statement. Or you forgot a closing/opening parens or brace. Hopefully you are using a proper code editor to edit your code. Such editors will highlight your code and indent it properly.


Do you know c++ programming? I need help, I can't get this one to work.?

I'm supposed to make a program that generates 2 random numbers between 10-99 and then asks you for the answer, if you get it incorrect you have to keep trying again until you get it correct.











int main ( )


{





int answer=0;


int value=0;


int ran1=0;


int ran2=0;


int total=0;


int high=0;


int low=0;








srand ((unsigned int) (time (0)));


cout %26lt;%26lt; rand ()%26lt;%26lt; endl;


cout %26lt;%26lt; rand ()%26lt;%26lt; endl;


value = (rand() % 90) +10;


cout %26lt;%26lt; "What is the first number generated? ";


cin %26gt;%26gt; ran1;


cout %26lt;%26lt; "What is the second number generated? ";


cin %26gt;%26gt; ran2;


cout %26lt;%26lt; "What is the total? ";


cin %26gt;%26gt; total;


total=ran1+ran2;


while (answer%26lt;total || answer%26gt;total)


{


cout %26lt;%26lt;"Incorrect!"%26lt;%26lt;endl;


cout %26lt;%26lt;"Please, try again.";


cin %26gt;%26gt; answer;


}


cin %26gt;%26gt; total;








return 0;


}

Do you know c++ programming? I need help, I can't get this one to work.?
//Try this....


#include "stdafx.h"


#include %26lt;ctime%26gt;


#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;





using namespace std;





int main()


{





srand((unsigned)time(0));


int rand1 = (rand()%90)+1;


int rand2 = (rand()%90)+1;


int int1, int2, total, user_total;


total = rand1 + rand2;





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


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





cout %26lt;%26lt; "What is the first number generated? ";


cin %26gt;%26gt; int1;


cout %26lt;%26lt; "What is the second number generated? ";


cin %26gt;%26gt; int2;


cout %26lt;%26lt; "What is the total? ";


cin %26gt;%26gt; user_total;


while (total != user_total)


{


cout %26lt;%26lt;"Incorrect!"%26lt;%26lt;endl;


cout %26lt;%26lt;"Please, try again."%26lt;%26lt;endl;


cin %26gt;%26gt; user_total;





}


cout%26lt;%26lt;"Correct!"%26lt;%26lt;endl;


cout%26lt;%26lt;"The total is "%26lt;%26lt;total%26lt;%26lt;endl;





return 0;


}
Reply:// Try more like this:





int main()


{


int ran1, ran2, guess1, guess2, guesstotal, totalrand;





srand ((unsigned int) (time (0)));


while (1) //loop forever...


{


ran1= (rand() % 90) +10;


ran2= (rand() % 90) +10;


totalrand=ran1+ran2;





cout %26lt;%26lt; "What is the first number generated? ";


cin %26gt;%26gt; guess1;


cout %26lt;%26lt; "What is the second number generated? ";


cin %26gt;%26gt; guess2;


cout %26lt;%26lt; "What is the total? ";


cin %26gt;%26gt; guesstotal;





if(guesstotal == totalrand)


{


cout %26lt;%26lt; "Very good!" %26lt;%26lt; endl;


break; //break the loop, user succeeded...


}


else


{


cout %26lt;%26lt;"Incorrect!"%26lt;%26lt;endl;


cout %26lt;%26lt;"Please, try again.";


}


} //end while()





return 0;


}


/* Discussion: note we're still not using all the variables to potential---and I wouldn't call this code finished ---but I think you're alot closer to where you want to be....





This code also depends on if you want to keep generating new random numbers or not. If you don't want new random numbers each time, move that portion of code outside the loop. I'm not really clear (sorry) on which it is you want...new random numbers each time, or re-using them 'til user guesses. But hopefully this helps you either way...


*/

kudzu

Question in c++ for square roots?

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


#include %26lt;iostream.h%26gt;//needed for cout message


#include %26lt;math.h%26gt;// need got math


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


#include %26lt;string.h%26gt;// needes for strings


void startup();


void method(double sqrt(double num));


int main()


{


startup();


method(double sqrt(double num));


getch();


return 0;


}


void startup()


{


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


cout%26lt;%26lt;"Jan 24, 2008"%26lt;%26lt;'\n';


cout%26lt;%26lt;"pg162 problem 9.1.2"%26lt;%26lt;'\n';


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


}


void method(double sqrt(double num))


{


int num;


cout%26lt;%26lt;"Enter a number to be squared rooted: ";


cin%26gt;%26gt;num;


cout%26lt;%26lt;num;


}


i'm trying to find the sqrt of the number the user is going to enter but my book just says that the function is sqrt. plz help. thx





sry there is more, i have to make the outcome as like if the num is 45 then it should equal 3 times square root of 5. help plzz thx

Question in c++ for square roots?
#include %26lt;conio.h%26gt;// needed for getch


#include %26lt;iostream.h%26gt;//needed for cout message


#include %26lt;math.h%26gt;// need got math


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


#include %26lt;string.h%26gt;// needes for strings





void startup();


void method();





int main()


{


startup();


method();


getch();


return 0;


}


void startup()


{


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


cout%26lt;%26lt;"Jan 24, 2008"%26lt;%26lt;'\n';


cout%26lt;%26lt;"pg162 problem 9.1.2"%26lt;%26lt;'\n';


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


}


void method()


{


int num;


cout%26lt;%26lt;"Enter a number to be squared rooted: ";


cin%26gt;%26gt;num;


cout%26lt;%26lt;sqrt(num);


}


C++ programing project I am stumped, I need to access the files from studenttests.dat and I can't figure?

#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;fstream%26gt;


#include %26lt;string%26gt;


#include %26lt;E:studenttests.dat%26gt;


using namespace std;








ifstream if1;











string LASTNAME, FIRSTNAME, TEST ONE, TESTTWO, TEST THREE;








int TESTONE ,TESTTWO ,TESTTHREE;


double FINALAVG;





void main()


{


cout%26lt;%26lt; " S T U D E N T G R A D E R E P O R T "%26lt;%26lt; endl ;


cout%26lt;%26lt; endl ;


cout%26lt;%26lt; "STUDENT TEST TEST TEST FINAL " %26lt;%26lt; endl ;


cout%26lt;%26lt; " NAME ONE TWO THREE AVG " %26lt;%26lt; endl ;


cout%26lt;%26lt; endl;











if1.open ("E:studenttests.dat");





if1%26lt;%26lt;setw(5)%26gt;%26gt;LASTNAME%26lt;%26lt;setw(21)%26lt;%26lt;FIRSTN...


%26lt;%26lt;LASTNAME%26lt;%26lt;FIRSTNAME%26lt;%26lt;TESTONE%26lt;%26lt;TESTTWO%26lt;...


%26lt;%26lt;LASTNAME%26lt;%26lt;FIRSTNAME%26lt;%26lt;TESTONE%26lt;%26lt;TESTTWO%26lt;...


cout%26lt;%26lt;endl;





if1.close;


and I am getting 3 errors or this????





ompiling...


Project3.cpp


e:\studenttests.dat(1) : error C2146: syntax error : missing ';' before identifier 'Bill'


e:\studenttests.

C++ programing project I am stumped, I need to access the files from studenttests.dat and I can't figure?
What are you doing, including studenttests.dat? You only include header files. studenttests.dat is an external file that has nothing to do with your C++ compilation process.





%26gt;%26gt; ifstream if1;





Move it out of the global space and into the main. Learn to not pollute your program with global variables.





%26gt; string LASTNAME, FIRSTNAME, ...





All caps names? Either make them all lowercase, or use a more sensible naming convention like CamelCaps (with the first letter lowercase).





And the whole no all caps names rule applies. Even though it's valid syntax, it's horrible convention.





%26gt; void main()





int main(). Not void main(). int. int. Can't repeat that enough.





%26gt; if1.open ("E:studenttests.dat");





Remove the E: part. Put studenttests.dat in the same folder as your executable program.





Get a proper book on C++ programming. If you don't want to do so, take a look at http://www.cprogramming.com/tutorial.htm...
Reply:"Project3.cpp


e:\studenttests.dat(1) : error C2146: syntax error : missing ';' before identifier 'Bill'


e:\studenttests."





Why is it trying to compile studenttests.dat? That looks like a problem. Do not compile studenttests.dat.
Reply:Remove The Following Statement


#include %26lt;E:studenttests.dat%26gt;


to resolve the problem.





There is another mistake in the program (i.e) in statement:


string LASTNAME, FIRSTNAME, TEST ONE, TESTTWO, TEST THREE;





Remove Space beteween TEST and ONE, and TEST and THREE,





Now Use the following statment instead:


string LASTNAME, FIRSTNAME, TESTONE, TESTTWO, TESTTHREE;





Also You can not declare 2 variables with different data types with same name. so remove the following statments:





int TESTONE ,TESTTWO ,TESTTHREE;


double FINALAVG;


Another question about my c++ program i dont know what wrong with it?

i dont know what do cout at the end so i just couted amount i think its wrong. plzzz help.


#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()


{


float amount, quaters=0, dimes=0, pennies=0, nickels=0;








cout%26lt;%26lt;"Enter amount of money less than $1: $ ";


cin%26gt;%26gt;amount;





quaters = amount / 25;


amount = quaters * 25;





dimes = amount / 10;


amount = dimes * 10;





pennies = amount / 1;


amount = pennies * 1;





nickels = amount / 5;


amount = nickels * 5;





cout%26lt;%26lt;"Your amount divided is: "%26lt;%26lt;amount%26lt;%26lt;'\n';


}

Another question about my c++ program i dont know what wrong with it?
If you are requesting the amount in the form of 0-99 you should enter it into an integer. You can then use the mod operator to accomplish what you need.





quarters=amount/25;


amount=amount%25;





dimes=amount/10;


amount=amount%10;





etc.
Reply:So that we can know what you are trying to do, please put comments in your program. Also please tell us what you are entering and what is coming out. THe way it is written, what comes out should be the same as what you put in, since you restore "amount" over and over.


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


OK, since you want to print out the number of quarters, etc, then print out the quarters, not the amount. In other words,





cout %26lt;%26lt; "The number of quarters is " %26lt;%26lt; quarters%26lt;%26lt;"\n";





and so on for the other types of coins.


C++ Programming Question. How do I insert a loop to continually repeat this entire sequence?

#include %26lt;iostream%26gt;





using namespace std;





int main()


{


int pH;


cout%26lt;%26lt;"please tpye the pH to the nearest whole number: ";


cin%26gt;%26gt; pH;


cin.ignore();


if ( pH %26lt; 7 ) {


cout%26lt;%26lt;"This pH level is acidic \n";


}


if ( pH %26gt; 7 ) {


cout%26lt;%26lt;"This pH level is basic \n";


}


if ( pH == 7 ) {


cout%26lt;%26lt;"The pH is neutral \n";


}


if ( pH %26lt; 0 ) {


cout%26lt;%26lt;"Please reenter a pH level between 0 and 14 \n";


}


if ( pH %26gt; 14 ) {


cout%26lt;%26lt;"Please reenter a pH level between 0 and 14 \n";


}


cin.get();


}


--- How do you insert the loop here to continually repeat the above when a user hits enter? Thanks for any help.

C++ Programming Question. How do I insert a loop to continually repeat this entire sequence?
wouldn't you just surround it with a do...while block?





For example,





do {


cout %26lt;%26lt; "Please enter...





%26lt;rest of your code%26gt;





} while (pH !='Q');
Reply:int main()


{


int pH;


while( 1 ) {


cout%26lt;%26lt;"please tpye the pH to the nearest whole number: ";


cin%26gt;%26gt; pH;


cin.ignore();





if ( pH %26lt; 0 ) {


cout%26lt;%26lt;"Please reenter a pH level between 0 and 14 \n";


} else if ( pH %26gt; 14 ) {


cout%26lt;%26lt;"Please reenter a pH level between 0 and 14 \n";


} else if ( pH %26lt; 7 ) {


cout%26lt;%26lt;"This pH level is acidic \n";


} else if ( pH %26gt; 7 ) {


cout%26lt;%26lt;"This pH level is basic \n";


} else if ( pH == 7 ) {


cout%26lt;%26lt;"The pH is neutral \n";


}


}


}
Reply:Why would you want to enter an infinite loop. This is a dangerous memory and cpu hog if not done carefully. You should always have an exit point or at least a sleep point so you don't chew the cpu up.





/*Very bad PsuedoCode


Yourloop


Do Something


Sleep for 20 seconds


Pick an exit situation here...never CONTINUOUSLY loop, you want to exit sometime in the future


Loop
Reply:im not really sure wat u mean.......? could you explain a bit more


wat do u want to repeat?/

garland flower

C++ problem?

we want day health to change when we attack





plz help





#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;





int main(void)


{


int dayhealth = 100;


int plhealth = 50;


string name;


char answer;


int attack = 10;





cout %26lt;%26lt;"gahhh?" %26lt;%26lt; endl;


cin %26gt;%26gt; name;





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





cout%26lt;%26lt; "player" %26lt;%26lt; plhealth %26lt;%26lt; "\n\nday" %26lt;%26lt; dayhealth %26lt;%26lt; endl;





cout%26lt;%26lt; "atk?" %26lt;%26lt; endl;


cin%26gt;%26gt; answer;





if (answer = 'yes')


{


cout %26lt;%26lt; "gahhh" %26lt;%26lt; dayhealth - attack %26lt;%26lt; endl;





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


}








system("PAUSE");


return EXIT_SUCCESS;


}

C++ problem?
You are never taking anything away from dayhealth. The statement dayhealth-attack does the subtraction for the print statement but it does not assign it back to day health. If you want to assign it back you should use -= instead of just minus.





Also the comparison of answer == 'yes' is still not correct because answer is a single character and can only be compared to a single character =='y'
Reply:hmmm.. what's the problem?


if the problem is that nothing happens when you execute this code. It must be the if statement.


"if(answer='yes')" should be "if(answer=='yes')"





^^,


C++ help please!! i am getting a buch of errors - i don't how to fix them.i am just a beginer please help me!!

this program should display shipping charge based on the ZIP code entered by the user. this is my code:


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::string;


using std::setprecision;


using std::fixed;








int main()


{


//declare variables


int zipCode = 0;


string beginZipCode = "";





//get input from user


cout %26lt;%26lt; "Enter a zip code: " %26lt;%26lt; endl;


cin %26gt;%26gt; zipCode;





//calculate and display taxes and net pay


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


{


if (zipCode.lenght() != 5)


cout %26lt;%26lt; "The zip code must contain five digits! " %26lt;%26lt; endl;


else


{


beginZipCode = zipCode.substri(0, 3);





if (beginZipCode == "605")


cout %26lt;%26lt; "Shipping charge: $25.00" %26lt;%26lt;endl;


else if (beginZipCode == "606")


{


cout %26lt;%26lt; "Shipping charge: $30" %26lt;%26lt;endl;


else


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


}


}


}

C++ help please!! i am getting a buch of errors - i don't how to fix them.i am just a beginer please help me!!
Without knowing what error you are getting, it is tough to help you out. One error I could spot in the code was in the following line





if (zipCode.lenght() != 5)





there is no method in the String class called lenght. The correct method is length()
Reply:'lenght()' is misspelled
Reply:Couple of errors I spotted:


1) you declared zipCode to be an INT, but you're trying to use it like a String. while(zipCode != "x"... won't work., nor will zipCode.length().





2) Misspelled length()





3) Wrong method: substri() should be substr()





Sometimes it helps to put line numbers so I could have told you which line had the above problems.


Help with c++ please?

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


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


#include %26lt;ctype.h%26gt; // needed for toupper


#include %26lt;stdlib.h%26gt;// needed for rand


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





using namespace std;





int main ( )


{


int months[12]={31,28,31,30,31,30,31,31,30,3...


int month[2]={0,0};


int dan[2]={0,0};


int daystart=0;


int munth=0;


int latot=0;


int year=-1;





cout %26lt;%26lt; "Enter starting month #: ";


cin %26gt;%26gt; month[0];


while(month[0]%26lt;0 || month[0]%26gt;12)


{


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


cin %26gt;%26gt; month[0];


}





cout %26lt;%26lt; "Enter starting day #: ";


cin %26gt;%26gt; dan[0];


while(dan[0]%26lt;0 || dan[0]%26gt;31)


{


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


cin %26gt;%26gt; dan[0];


while (month[0]==2 ||


month[1]==2 %26amp;%26amp; dan[0]%26gt;28)


{


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


cin %26gt;%26gt; dan[0];


}


}





cout %26lt;%26lt; "Enter ending month #: ";


cin %26gt;%26gt; month[1];


while(month[1]%26lt;0 || month[1]%26gt;12)


{


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


cin %26gt;%26gt; month[1];


}

Help with c++ please?
No.





Do your own homework, or ask a specific question if you are stuck.


//c++ help making a pyramid of $'s;?

its supposed to be like


....$


..$$$


$$$$$





(without the .'s)





heres what i have





for(loopCounter = 1; loopCounter %26lt;= 5; loopCounter += 2);


{


dollarsToPrint = loopCounter;


spacesToPrint = (5 - dollarsToPrint) / 2;


int i;


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


{


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


}


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


{


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


}


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


}





yes, everything is declared, it just loops infinately








heres another attempt, i just started over and all it does is 1 $ sign





for (loopCounter = 1; loopCounter %26lt;= 5; loopCounter += 2);


{


dollarsToPrint = loopCounter;


spacesToPrint = (5 - dollarsToPrint) / 2;


int i;


for (i = 1; i %26lt;= spacesToPrint; i++) //print spaces


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


//print dollar signs


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


cout %26lt;%26lt; endl;


}





i appreciate any help as i am a n00blet

//c++ help making a pyramid of $'s;?
You have a semi-colon at the end of your 'for' statement:





for (loopCounter = 1; loopCounter %26lt;= 5; loopCounter += 2);





Even with that fixed, you're only printing one $ per pass through your outer loop, when you need 1, 3, 5, etc. You're definitely on the right track, but just have some problems with your counters and computations. If you walk through it on paper, you should quickly see what's happening.





There are many different ways to code this, but I thought I'd try to fix your approach, rather than offer you my own. Check this out:





const int pyramidBaseWidth = 5;


const int pyramidHeight = pyramidBaseWidth/2 + 1;





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





for (int loopCounter = 0; loopCounter %26lt; pyramidHeight; loopCounter++) {


int spacesToPrint = pyramidHeight - loopCounter - 1;


int dollarsToPrint = loopCounter * 2 + 1;


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


for (int i = 0; i %26lt; dollarsToPrint; i++) cout %26lt;%26lt; "$";


cout %26lt;%26lt; endl;


}


return 0;


}





It'll work for any value you plug in for pyramidBaseWidth. Even if your problem statement explicitly specified 5 for the width of your pyramid base, get in the habit of using constants, as I've done, rather than using hardcoded numbers, as you did with 5 in your code. It's a good habit to get into; it's almost never acceptable to use hardcoded values.
Reply:you almost had it with your first program...


i took that code and adjusted it so it should run.


Im at work and couldnt test it, but it looks good to me





for (loopCounter = 1; loopCounter %26lt;= 5; LoopCounter +=2)


{


dollarsToPrint = loopCounter;


spacesToPrint = (5 - dollarsToPrint)/2;





for (int i = 1; i %26lt;= spacesToPrint; i ++)


{


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


}


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


{


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


}


cout%26lt;%26lt; endl;


}





looks like your problem stemmed from the extra


semicolon on the first loop and not assigning a


value to the "i" in the second loop
Reply:For your second attempt:





- Remove the semicolon at the end of your top for statement.


- Add curly brackets after your second for statement, enclosing everything you want to be executed in that for loop.





Examine your first for statement. Why is loop counter being incremented by 2? The outer loop will only execute twice before it is no longer %26lt;= 5





Good luck!

blazing star

Its a c++ program, plz helpppp?

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


#include %26lt;iostream.h%26gt;//needed for cout message


#include %26lt;math.h%26gt;// need got math


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


#include %26lt;string.h%26gt;// needes for strings


void startup();


void method(double sqrt(double num));


int main()


{


startup();


method(double sqrt(double num));


getch();


return 0;


}


void startup()


{


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


cout%26lt;%26lt;"Jan 24, 2008"%26lt;%26lt;'\n';


cout%26lt;%26lt;"pg162 problem 9.1.2"%26lt;%26lt;'\n';


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


}


void method(double sqrt(double num))


{


int num;


cout%26lt;%26lt;"Enter a number to be squared rooted: ";


cin%26gt;%26gt;num;


cout%26lt;%26lt;num;


}








i'm trying to find the sqrt of the number the user is going to enter but my book just says that the function is sqrt. plz help. thx

Its a c++ program, plz helpppp?
http://www.cplusplus.com/reference/clibr...





In function method fuggetyerparameter. declare int num as double num and replace the line "cout%26lt;%26lt;num;" with "cout%26lt;%26lt;sqrt(num);"





Programs that use conio.h tend to be c, not c++ because it is a c library. For getch(); you might try "system("pause");". System is in the stdlib.h header, which I believe is #included in a couple of the headers you are using.





Now can I go back to sleep?


Slight problem with my c++ program?

10 11 12 13 14 15 16 17 18 19 20





100


99


98


97


96


95


94


93


92


91


90





Enter number 1: 10


Enter number 2: 20


Enter number 3: -5


Enter number 4: 7


Enter number 5: 23





The sum is 55.





This is the samle output that I am supposed to reproduce with codes. I got.





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





int main () {


int counter, num, sum, numValues;





cout %26lt;%26lt; "Loop Examples 2" %26lt;%26lt; endl %26lt;%26lt; endl;





counter = 10;


do {


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


counter++;


} while (counter %26lt;= 20);





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





counter = 101;


do {


counter--;


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


} while (counter %26gt; 90);


cout %26lt;%26lt; endl;





numValues = 1;


do {





cout %26lt;%26lt; "Enter number" %26lt;%26lt; numValues %26lt;%26lt; ": " ;


cin %26gt;%26gt; num;


numValues++;


sum+= num;


} while (numValues %26gt; 0 %26amp;%26amp; numValues %26lt; 6);


cout %26lt;%26lt; endl;


cout %26lt;%26lt; "The Sum is: " %26lt;%26lt; sum %26lt;%26lt; endl;


return 0;





}


My problem is when i compile and run this program, the Sum does NOT come out right.

Slight problem with my c++ program?
You're problem is right here:





sum += num;





sum isn't initialized to 0. It's garbage when it starts out. That's why your output is wrong.





When you declare sum do this:





int sum = 0;
Reply:Where do you assign an initial value to sum? When you declare a value in C++, its initial value is whatever happens to be at that spot of memory at that time. You need to make sure to set sum=0; before the loop that uses it.





A side note:


Using for loops will make your program simpler and easier to read. Here is the code with the sum variable initialized to 0 and using for loops:





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





int main () {


int num, sum, numValues;





cout %26lt;%26lt; "Loop Examples 2" %26lt;%26lt; endl %26lt;%26lt; endl;





for (int counter = 10; counter %26lt;=20; counter++)


{


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


}


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





for (counter = 100; counter %26gt;= 90; counter--)


{


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


}


cout %26lt;%26lt; endl;





sum = 0;


for (numValues = 1; numValues %26lt; 6; numValues++)


{


cout %26lt;%26lt; "Enter number" %26lt;%26lt; numValues %26lt;%26lt; ": " ;


cin %26gt;%26gt; num;


sum+=num;


}


cout %26lt;%26lt; endl;


cout %26lt;%26lt; "The Sum is: " %26lt;%26lt; sum %26lt;%26lt; endl;





return 0;


}
Reply:use sum += num; to correct your problem.








Dornessa


http://onlinedownlinebuilders.com


C++ putting formula?

the answers do not appear.... how should i put formula correctly?





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


int main ()


{


//conditional statement


int l;


int w;


int a;


int p;


cout%26lt;%26lt;"enter the length:";


cin%26gt;%26gt;l;


cout%26lt;%26lt;"enter the width:";


cin%26gt;%26gt;w;


if (l%26lt;=w)


{a=l*w;


cout%26lt;%26lt;"the area of the rectangle is:";


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


else(l%26gt;w);


{p=2*l+2*w;


cout%26lt;%26lt;"the perimeter of the rectangle is:";


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


return 0;


}

C++ putting formula?
else(l%26gt;w);





remove the semikolon





also, you don't print the result, you just print


cout %26lt;%26lt; "the area of the rectangle is: ";


instead of


cout %26lt;%26lt; "the area of the rectangle is: " %26lt;%26lt; a;
Reply:try with writing


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


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


if the problem not solved contact me i will provide u another program for this
Reply:in your else statement, you shouldn't explicitly say:


else(l%26gt;w)


else() is enough...unless of course you wanted to say:





else if(l%26gt;w)...but from your code i didn't get that impression.
Reply:u should also print out the variable 'p' which is ur final answer


C++ help please!?

Basically I'm making a program that asks users to input the number of points they want to enter, and then asks for the x value and y value of these points to calculate the slope and y-intercept, and further find the linear regression of the graph.





I'm at something like this:





#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


#include %26lt;iomanip%26gt;


using namespace std;





int main()


{


int n;


double array1[100];


double array2[100];





cout%26lt;%26lt;"Enter the number of points: \n";


cin%26gt;%26gt;n;





while (n%26lt;=1)


{


cout%26lt;%26lt;"Please enter a different number of points: \n";


cin%26gt;%26gt;n;


}





for(int k=1; k%26lt;=n; k++)


{


cout%26lt;%26lt;"Enter the value of the x coordinate: \n";


cout%26lt;%26lt;"x_"%26lt;%26lt;k%26lt;%26lt;endl;


cin%26gt;%26gt;array1[100];





cout%26lt;%26lt;"Enter the value of the y coordinate: \n";


cout%26lt;%26lt;"y_"%26lt;%26lt;k%26lt;%26lt;endl;


cin%26gt;%26gt;array2[100];


}





return 0;


}





And I get an error"Run-Time Check Failure #2 - Stack around the variable 'array2' was corrupted."


How are the numbers assigned in the array to access them to create the formula for the slope, and how do I fix this error?

C++ help please!?
array1 and array2 you can only have the index from 0 to 99. basically your program is buffer overflow. inside the loop you should code like cin %26gt;%26gt; array1[k-1] (if that's what you want, as as the array2). Good luck.
Reply:I think you got the logic all wrong, you may want to reconsider this order. You don't really need arrays to hold 4 numbers total. All you need to calculate the slope and y-intercept are 4 numbers, (x1, y1), (x2, y2)





You also have syntax errors: what's the k doing there? (example: cout%26lt;%26lt;"y_"%26lt;%26lt;k%26lt;%26lt;endl;


you never defned 'k'.....





The easiest would be a straigt forward enter the first point as (x, y)


do a cin%26gt;%26gt;x1%26gt;%26gt;y1;





prompt for second point as (x,y)


do cin%26gt;%26gt;x2, y2;





now you have all you need to calculate slope and y-intercept.


you have to define these. something like


double s;


int y_intercept;





s = (x2-x1)/(y2-y1);





then do the y intercept.





then output these values


cout%26lt;%26lt;"the slope with the given points is " %26lt;%26lt;s%26lt;%26lt;endl;


cout%26lt;%26lt;"the y intercept with the given points is " %26lt;%26lt;y_intercept%26lt;%26lt;endl;





Send me an email if you want more help with it.

imperial

C++ Program Help?

//hw8 5 functions


#include %26lt;iostream%26gt;


using namespace std;





int sumOfDigits(int n){


int sum=sum+n;


return sum;


}





int squared(int n) {


int answer=n*n;


return answer;


}





int factorial(int n) {


if (n%26lt;0) return 0;


int factorial=1


while (n%26gt;1) {


factorial *= n--;


return factorial;


}





int Sn(int n) {


int n= sum+n, n++;


return Sn;


}





void drawTriangle(int n) {


for (n=1; n%26lt;=x; n++) {





}


int main () {


int n;


cout %26lt;%26lt; "Enter a number,n: "%26lt;%26lt;endl;


cin %26gt;%26gt; n;


cout %26lt;%26lt; "The sum of digits of n are: "%26lt;%26lt;sumofDigits%26lt;%26lt; endl;


cout %26lt;%26lt; "The number n squared is: "%26lt;%26lt;squared%26lt;%26lt; endl;


cout %26lt;%26lt; "The number n factorial is : "%26lt;%26lt;factorial%26lt;%26lt; endl;


cout %26lt;%26lt; "The sum of all natural numbers from 1 to n is: "%26lt;%26lt;Sn%26lt;%26lt; endl;


cout %26lt;%26lt; "The triangle will look like this: "%26lt;%26lt;drawTriangle%26lt;%26lt; endl;


return 0;

C++ Program Help?
It looks mostly correct, but you should indent after the curly brackets.
Reply:int factorial(int n) {


if (n%26lt;0) return 0;


int factorial=1


while (n%26gt;1) {


factorial *= n--;


return factorial;


}





I'm no expert, but right there, I don't think you can initalize it twice. Also, your while loop has no ending bracket.
Reply:thats correct!


C++ error on line 28, Could you please tell me what is wrong with it? I'm new to C++?

//Ch3AppE03.cpp


//Calculates and displays a commission amount


//Created/revised by 1102640 on 1-19-08





#include %26lt;iostream%26gt;





First person that helps correct my error will get the ten points.


using std::cout;


using std::cin;


using std::endl;





int main()


{








//declare variables


double sales = 0.0;


double rate = 0.0;


double commission = 0.0;





//enter input items





cout %26lt;%26lt; "Enter the sales: ";


cin %26gt;%26gt; sales;


cout %26lt;%26lt; "Enter the commission rate: ";


cin %26gt;%26gt; rate;





//calculate commission


commission = sales * commission rate;








//display commission


cout %26lt;%26lt; "Your commission is: " %26lt;%26lt; commission %26lt;%26lt; endl;


return 0;


} //end of main function





I know the error is on the calcaulation line (28) but dunno what is wrong with it.

C++ error on line 28, Could you please tell me what is wrong with it? I'm new to C++?
commission = sales * commission rate;





You probably want:


commission = sales * rate;
Reply:what country are you from?
Reply:Variable commission rate is not declared!!


it should be


commission = sales * rate;


Help with C++. how do i redefine the code below making it a class that has private function and variables?

#include %26lt;iostream%26gt;


#include %26lt;istream%26gt;





using namespace std;


class CDAccount


{


double balance;


double interest_rest;


int term; //months until maturity


};


void get_data (CDAccount%26amp; the_account);





int main()


{


CDAccount account;


get_data(account);





double rate_fraction, interest;


rate_fraction = account.interest_rest/100.0;


interest = account.balance*rate_fraction*(account.t...


account.balance = account.balance + interest;





cout.setf(ios::fixed);


cout.setf(ios::showpoint);


cout.precision(2);


cout %26lt;%26lt; "When your CD matures in "


%26lt;%26lt; account.term %26lt;%26lt; "months,\n"


%26lt;%26lt; account.balance %26lt;%26lt; endl;


return 0;


}


void get_data(CDAccount%26amp; the_account)


{


cout %26lt;%26lt; "Enter account balance: $";


cin %26gt;%26gt; the_account.balance;


cout %26lt;%26lt; "Enter account interest rate: ";


cin %26gt;%26gt; the_account.interest_rest;


cout %26lt;%26lt; "Enter the number of months until maturity\n"


%26lt;%26lt; "(must be 12 or fewer months): ";


cin %26gt;%26gt; the_account.term;


}

Help with C++. how do i redefine the code below making it a class that has private function and variables?
Move the 'get_data' function to within the braces of the class. Since it's inline, you don't need the function prototype definition.