Sunday, August 2, 2009

Please help!!! C++ Assignment?

I need help with this question. %26gt;"%26lt;





This is the instruction:


1.Your review of the program "main" will reveal that an array of "Account" objects is created; group[6].


- add a loop to the main( i.e. for loop) to create a deposit for each group element.


- add a loop to the main( i.e. for loop) to output the balance of each group element.


- the output loop should also identify which group element is being output.





ex.


Group 1 Account:


Balance : 300





Group 2 Account:


Balance : 600


===============================


#include %26lt;iostream%26gt;


using namespace std;


class Account


{


long balance;


public:


void deposit (long amount)


{


balance += amount;


}


void withdraw (long amount)


{


balance -= amount;


}


void status ()


{


cout %26lt;%26lt; "balance : " %26lt;%26lt; balance %26lt;%26lt; endl;


}





Account (long initialAmount = 0)


{


balance = initialAmount;


}


~Account ()


{


cout %26lt;%26lt; " transfer " %26lt;%26lt; balance %26lt;%26lt; " to manager " %26lt;%26lt; endl;


}


};


int main ()


{


Account mine, yours (100), group[6];





mine.deposit (500); // now balance should be 500





mine.status (); // "The balance is : 500"





yours.status (); // "The balance is : 100"





yours.deposit (300);


yours.status (); // "The balance is : 400"





mine.withdraw (600); // now in the red





mine.status (); // "The balance is : -100"





return 0;


}

Please help!!! C++ Assignment?
I am confused as to how you can understand how to make object method calls and not know how to use a loop.





Here is the first loop to get you started but it is your job to do your assignments.





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


{


group[i].deposit(100);


}
Reply:What's your question?


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.


Can someone help me with a c++ program please?

hey i suck at this, i need to write a program that plays the game hangman, i wrote some of it, not even sure if any of it is right though.


I'll post the programs and then I'll ask questions.





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


#include %26lt;string%26gt;


using namespace std;











int main(){


string myWords[1000];


short wordCount=0;


ifstream word;


word.open("dictionary.txt");


while (!word.eof()){


word%26gt;%26gt;myWords;


wordCount++;


}


int x = rand() % wordCount + 0;


string question = myWords[x];








return 0;


}











void drawGallows(char a[]){


char gallows[10]{





" //========= ",


" || ",


" || ",


" || ",


" || ",


" || ",


" || ",


" || ",


"/||\ ",


"

Can someone help me with a c++ program please?

Reply:__________";


}
Reply:Well, you seem to have your gallows on the right track, so I'll omit that. My example uses streamstreams in lieu of a file since I didn't feel like creating a file (and you already have the code for that).





For the answer, I'm taking the string's length and turning all its characters into asterisks. Once a letter is found, the string 'ourword' character is also turned into an asterisk. Once all the characters in 'ourword' are asterisks, then it matches the answer, ie. * * * * * *.





[code]





#include %26lt;string%26gt;


#include %26lt;sstream%26gt;


#include %26lt;iostream%26gt;





int found;


string ourword; //for example, copies an array word for puzzle


string answer; //used for comparison


int wrong=0; //must initialize this for increment





void startgame()


{


std::cout%26lt;%26lt;"
Reply:||\n"; //build this function to display hangman


}





//////////////////////////////////////...


string%26amp; FindChar(string%26amp; look_for_letter,


const string%26amp; findMe) {


//start at pos 0


size_t letter = look_for_letter.find(findMe, 0);


// look for letter


if (letter != string::npos) //string, find and replace function


found=1;


else


found=0;


}


//////////////////////////////////////...





string letter; //we declare this globally since it's used both


//inside and outside of call_for_letter function.





void call_for_letter()


{


letter.erase();


std::cout%26lt;%26lt;"please enter a letter";


std::cin%26gt;%26gt;letter;


}





std::string sentence="I am a string and I want to add myself into"


" an array ";


std::stringstream as; //in lieu of reading from file I'm using a


//stringstream - I'm declaring that here.





std::stringstream ar; //we'll use this stream to buffer sentence


//for reading into an array





std::string word; //our string word once found


std::string fullmonty[1024]; //size limit


std::string billy [13]; //our array size -- arrays begin at 0, not 1!


std::string entry; //our string to store underscore display


std::string underline="_"; //character to use for underscore


std::string asterisk="*"; //character to use for asterisk





int main ()


{


as %26lt;%26lt; sentence; //insert our sentence of words into stringstream


ar %26lt;%26lt; sentence;


for (int n=0 ; n%26lt;13 ; n++ ) //n12 - do not exceed array size


{


std::getline(as,word,' '); //word stops at whitespace


billy[n]=word; //begin inserting words into array beginning at 0


//as for loop advances, so does our array #





std::cout %26lt;%26lt; billy[n]%26lt;%26lt;std::endl; //print each array at its stored


}


std::cout%26lt;%26lt;std::endl;//for display spacing


std::cout%26lt;%26lt;billy[3]; //for show that array is stored.


std::cin.get(); //pause to look


ourword=billy[3]; //copy this array to ourword for puzzle word





//make underscores for display (entry string)





for (int y=0; y%26lt;ourword.length(); y++){ //use array.string


//length to determine how many underscores should be inserted


// into empty 'entry' string. Same for asterisks





entry.insert(0,underline,0); //insert underscores


answer.insert(0,asterisk,0); //insert asterisk *use to compare


//a completed answer





}





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


std::cout%26lt;%26lt;entry; //displays underscore (word length)





std::cin.get();





//add entire sentence into an array





std::getline(ar,word);


fullmonty[1024]=word;





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


std::cout%26lt;%26lt;fullmonty[1024];


std::cin.get();





//let's start a game





while (letter!="quit"){ //so long as user doesn't type in 'quit'


startgame();


call_for_letter(); //call our input function





FindChar(ourword,letter); //look for letter


string::size_type loc= ourword.find(letter); //id location





if( loc!= string::npos )


{


ourword.replace(loc,1,"*");


entry.replace(loc,1,letter);





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


std::cout%26lt;%26lt;ourword; //we replaced our found letter with an asterisk


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


std::cout%26lt;%26lt;entry; //above, we've replaced an underscore with letter found


startgame(); //return to input another letter


}





else{


std::cout%26lt;%26lt;"letter not found";


//here, you would handle wrong answer, count them,


//change hangman configuration in startgame strings.


wrong++; //keep track of wrong letters


std::cin.get();


startgame(); //return to input another letter if wrong answers are below min.


}





if (ourword==answer)


{


std::cout%26lt;%26lt;"You win!";


cin.ignore();


cin.get();


return 0;


}





}





return 0;


}


[/code]
Reply:I think you can consult a freelancers to get your code working


from


http://expert.myitcareer.org/

flower girl dresses

Can someone help me with a c++ program please?

hey i have this program thats supposed to read in info about students from a file organize and print it out, then read in some more info and calculate the gpa and print that out as well.





I have the program done, but for some reason it doesnt work, when i run it it outputs this:





record #0 from readdata:


from SetAll





it prints that out 20 times from numbers 0-19, the only error that the compiler gives me is


warning C4244: '=' : conversion from 'double' to 'int', possible loss of data





Im going to post my program in chunks since it spretty big someone help plz





#include%26lt;iostream%26gt;


#include%26lt;string%26gt;


#include%26lt;fstream%26gt;





using namespace std;





class Course{


string name;


char grade;


int hours;


public:


Course(){


name="";


grade=' ';


hours=0;


}


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


name=n;


grade=g;


hours=h;


}

Can someone help me with a c++ program please?
*looking up*


That is nice of you to try to help this guy, but you are providing Java solutions to a C++ problem. Doh!





EDIT:





This is fairly hopeless right now. If you look closer, you have pasted a lot of your code with lines that are truncated. (Search for the lines ending in "..."). I made a quick attempt to copy and paste your program, but it won't even compile (of course) as posted. If you address this there is a strong possibility that I will be able to help you fix this once and for all.





Edit #2 - Too funny! I offer to give a guy help, and someone gives me a "thumbs down". Beautiful!


Oh, and looking upwards again...


You consider it anal when I question when a guy puts out code in C++, and Java solutions that aren't necessarily even pertinent to his problem were provided? It is my opinion that you might be dwelling on the compiler "warning" that he incurred, which might not even be remotely related to his *problems*. He is apparently suffering far worse complications than some loss of precision from what he printed out. It looks like he is printing empty gibberish without any real results at this point. You are correct in what you have written, but this doesn't seem to be his worst issue from what he has written.


By the way, no offense or personal malice toward the guy on top, OK? I can now see that you are competent and not just some rube that copied and pasted from Sun's website.
Reply:DISCLAIMER: I use Java syntax and code in my answer, but it should be relatively the same in C++ (except for when i use parseDouble(). I write this disclaimer because some people are anal (*cough* the answerer below me *cough*). I know all too well that the program is in C++. Not stupid.





***************





In general, the way to fix this is to find the line of code throwing the error and cast (as an integer) the double variable you're attempting to assign to an integer. The rule of thumb here is that you can't assign an int to a double without some modification, or without a loss of precision.





Like this... (the (int) is where I'm doing the casting)





int test = (int) variable





(where variable is any double number).





Example:





THIS IS WRONG.


*******************


double testDouble = 2.3;


int test = testDouble;


*******************





THIS IS RIGHT.


*******************


double testDouble = 2.3;


int test = (int)testDouble;


*******************





You might also have to do something more complex, like





*******************


double testDouble = 2.3;


int test = Int.parseInt(testDouble);


*******************





(that was just an example, in that case, you wouldn't need to use parseInt(), a (int) caste would be sufficient.)





It all depends. Basically, though, you need to get the left side (integer) to be of the same as the right side. The way you have it, the right side is too complex for a much less complex integer, explaining why the compiler is yelling at you.


Is this C ++ problem right? can someone please check out!?

first of all i don't quite undurstand the problem and i want to know if it was understood right - this is the problem:





The Federal Reserve wants a program that can give the average interest rate on mortgages using data from four nationally ranked banks. Your tasks are to create a program that calculates the average of values stored in a one-dimensional double array named rates. The program should display the average rate on the screen.


Use the following data to:


Bank of America 6.2%, RBC Centura 7.1%, BB%26amp;T 5.9%, Federal Credit Union 6.0%


code:


#include %26lt;iostream%26gt;





using namespace std;





int main()


{


//declare array


double total = 0;


double average = 0;


double rate[4] = {6.2, 7.1, 5.9, 6.0};








// calculate sum


for (int x = 0; x %26lt; 4; x = x + 1)


total = total + rate[x];


//end for





//calculate and display average


average = total / 4;





cout %26lt;%26lt; "Average: " %26lt;%26lt; average %26lt;%26lt;endl;


return 0;


}//end of the displayAverage program

Is this C ++ problem right? can someone please check out!?
That is what the problem is asking you to do.





And I cannot see anything immediately wrong with it.





Only mathematically, you would not put in percent values as that but as 6.2% = 0.062, 7.1% = 0.071 and so on. But in the end your output would be in percent value. You just have to be aware of the difference between percent and the actual number.





Good job.
Reply:Your answer looks fine. Though I would change:


total = total + rate[x];


to


total += rate[x]; // cleaner


and I would limit the hard coded use of 4 to the array declaration.


using instead:


int count = sizeof(rate)/sizeof(double); // more universal


so if you could change the array size and nothing else would change.


Is this C ++ problem right? can someone please check out!?

first of all i don't quite undurstand the problem and i want to know if it was understood right - this is the problem:





The Federal Reserve wants a program that can give the average interest rate on mortgages using data from four nationally ranked banks. Your tasks are to create a program that calculates the average of values stored in a one-dimensional double array named rates. The program should display the average rate on the screen.


Use the following data to:


Bank of America 6.2%, RBC Centura 7.1%, BB%26amp;T 5.9%, Federal Credit Union 6.0%


code:


#include %26lt;iostream%26gt;





using namespace std;





int main()


{


//declare array


double total = 0;


double average = 0;


double rate[4] = {6.2, 7.1, 5.9, 6.0};








// calculate sum


for (int x = 0; x %26lt; 4; x = x + 1)


total = total + rate[x];


//end for





//calculate and display average


average = total / 4;





cout %26lt;%26lt; "Average: " %26lt;%26lt; average %26lt;%26lt;endl;


return 0;


}//end of the displayAverage program

Is this C ++ problem right? can someone please check out!?
It appears to be correct. I would change x = x+1 in the for loop to x++. To verify compile and run program and output should be "Average: 6.3"
Reply:i have no idea? but i do know you spelled understand wrong in the first sentence. you spelled it undurstand. but thanks for the points


How to get object name in c++?

hi ,





i am trying to get the object name, see the code below, but not able to find method, what could be the code in place of ???????.





#include "iostream"


using namespace std;


class A{


public:


int i;


void printObjectname(){


cout %26lt;%26lt; ????????;//%26lt;--what could be here, to print the object name as 'objectA'


}


};





int _tmain(int argc, _TCHAR* argv[])


{


A *objectA = new A();


objectA-%26gt;printObjectname();





return 0;


}

How to get object name in c++?
include the %26lt;typeinfo%26gt; header file and use function typeid()





http://publib.boulder.ibm.com/infocenter...
Reply:You have read the documentation of C++.
Reply:Sorry, there's no such thing in C++. You have to do this manually, i.e. change the code in every class:





virtual void printObjectname() { cout "A"; }





or even better:


virtual const char *getClassname() { return "A"; }





make the function virtual, then it can be overwritten in inherited classes.


Can someone help me with this C++ Inheritance problem?

#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;





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


{


class Printer {


protected:


int level;


public:


int getlevel();


};





int Printer::getlevel() {


return level;


}





system("PAUSE");


return EXIT_SUCCESS;


}





Why doesn't that work?

Can someone help me with this C++ Inheritance problem?
You can't put member function definitions from nested classes outside the class declaration, at least not with Dev-C++. I'm not sure if any compiler would support that. If you defined the getlevel function right after the declaration it would work:





class Printer {


...


int getlevel() { return level; }


...


};


...
Reply:You should use that protected varible within class and subclass of that class. then only it works.


public: within that class and outside of the class


protected:within that class and subclasses of that class


private:within that class only and cannot be accessed anywhere except within the class.


I need some help with a C++ program?

Hey I keep getting errors in this program and im not sure how to fix them, the program is supposed to tally up votes and print out winners in 6 different races. I'll post the program first and then my question:








#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


using namespace std;


void tally(int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;...


void print(int, int, int, int);





int main() {





cout%26lt;%26lt;"CS-114 Ballot Counter"%26lt;%26lt;endl%26lt;%26lt;endl;








cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Presidency:"%26lt;%26lt;endl;


print(1, 2, p1, p2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Vice Presidency:"%26lt;%26lt;endl;


print(3, 4, vp1, vp2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Secretary:"%26lt;%26lt;endl;


print(5, 6, s1, s2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Treasurer:"%26lt;%26lt;endl;


print(7, 8, t1, t2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Judge:"%26lt;%26lt;endl;


print(9, 10, j1, j2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Senator:"%26lt;%26lt;endl;


print(11, 12, sen1, sen2);





}

I need some help with a C++ program?
Undeclared identifier means you're using a variable that you haven't declared yet, and the compiler doesn't know what it is since you haven't told it. You need to declare p1, p2, vp1, etc before you ask the computer to print them. So at the very top of your main(), you need this statement:





int p1, p2, vp1 .... sen1, sen2;





You probably need to initialize all of them to zero too before you start; otherwise they will contain garbage values.





Next, if your program really executes in that order, I think you're trying to print the results before you actually collect them, so you need to open ballot.txt and tally up the votes before you call print(1, 2, p1, p2) etc.





Also, you're getting voter %26gt;%26gt; vote before your while loop, then doing it again once you get inside the loop, so you're always going to miss the first vote, unless the first entry in ballot.txt is a dummy value. You should delete the first voter %26gt;%26gt; vote; statement. If the file's empty, you'll get an error there anyway.





Your big long if block should be a switch-case statement instead of a series of if's. I believe the syntax is like this:





switch(vote)


{


case 1: p1++; break;


case 2: p2++; break;


default: cerr %26lt;%26lt; "Invalid vote";


}


The default case is for when none of the other cases match. You currently have p1+=0 for that, which makes no sense. You should just do nothing, or at least output an error message.





Good luck with your program!


Why should I use iterators rather than int for traversing through a list in C++.?

Why should I use


____________________


using namespace std;





vector%26lt;int%26gt; myIntVector;


vector%26lt;int%26gt;::iterator myIntVectorIterator;





// Add some elements to myIntVector


myIntVector.push_back(1);


myIntVector.push_back(4);


myIntVector.push_back(8);





for(myIntVectorIterator = myIntVector.begin();


myIntVectorIterator != myIntVector.end();


myIntVectorIterator++)


{


cout%26lt;%26lt;*myIntVectorIterator%26lt;%26lt;" ";


//Should output 1 4 8


}











Rather than


____________________





using namespace std;





vector%26lt;int%26gt; myIntVector;


// Add some elements to myIntVector


myIntVector.push_back(1);


myIntVector.push_back(4);


myIntVector.push_back(8);





for(int y=0; y%26lt;myIntVector.size(); y++)


{


cout%26lt;%26lt;myIntVector[y]%26lt;%26lt;" ";


//Should output 1 4 8


}

Why should I use iterators rather than int for traversing through a list in C++.?
Hi





well iterator have a main function, to access data from a container. when you have an stack, queue or some special container from STL you must use iterator to access the data inside those structure. It is impossible or very difficult to use other thing.





It is best practice to learn how to use iterator when you are dealing with complex data structures. Here i put some links.





good luck
Reply:safety, for one

edible flowers

Basic C++ Programming Help?

I am trying to figure out 3 simple things that I really can't figure out...





1) total odd numbers for my program when I input "3" scores of 53,54,67.


2) determine the highest number between those scores which is "67" .


3) How do I end the program by pressing "x" at the end, but it starts over when I press any other letter





#include %26lt;iostream%26gt;





using namespace std;





int main()


{





int counter = 1;


int totalodd = 0;


int num1;


int scores;


char letter;


int numbers;





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


cin%26gt;%26gt;num1;





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


cout%26lt;%26lt;"Enter an integer: "%26lt;%26lt;endl;


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


cin%26gt;%26gt;scores;





if ( ( scores % 2) != 0 )


totalodd = totalodd + scores;





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


totalodd++;





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

Basic C++ Programming Help?
The obvious bug I see is that your for() loops only apply to the next statement. If I enter 3 at the first prompt, you will execute the cout 3 times (showing the prompt over and over) then ask for a number 3 times, overwriting the first 2, then do the calculation on the last number only.





You need to group the prompt (cout0, cin, and calculation all within each pass of the loop by using { and } correctly.





Try:


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


{


cout%26lt;%26lt;"Enter an integer: "%26lt;%26lt;endl;





cin%26gt;%26gt;scores;





if ( ( scores % 2) != 0 )


totalodd = totalodd + scores;


}
Reply:A second issue is that you need to store the highest value somewhere, maybe in a variable named "highest". After the first value gets read into "scores", assign that as the highest value, for later values you must compare to the previous highest:





if (counter == 1) // 1st value is highest by default


highest = scores;


else if (scores %26gt; highest) // later values get compared to previous highest


highest = scores; // if new value%26gt;previous highest, then make that the highest


Basic C++ Programming Help?

I am trying to figure out 3 simple things that I really can't figure out...





1) total odd numbers for my program when I input "3" scores of 53,54,67.


2) determine the highest number between those scores which is "67" .


3) How do I end the program by pressing "x" at the end, but it starts over when I press any other letter





#include %26lt;iostream%26gt;





using namespace std;





int main()


{





int counter = 1;


int totalodd = 0;


int num1;


int scores;


char letter;


int numbers;





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


cin%26gt;%26gt;num1;





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


cout%26lt;%26lt;"Enter an integer: "%26lt;%26lt;endl;


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


cin%26gt;%26gt;scores;





if ( ( scores % 2) != 0 )


totalodd = totalodd + scores;





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


totalodd++;





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

Basic C++ Programming Help?
The obvious bug I see is that your for() loops only apply to the next statement. If I enter 3 at the first prompt, you will execute the cout 3 times (showing the prompt over and over) then ask for a number 3 times, overwriting the first 2, then do the calculation on the last number only.





You need to group the prompt (cout0, cin, and calculation all within each pass of the loop by using { and } correctly.





Try:


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


{


cout%26lt;%26lt;"Enter an integer: "%26lt;%26lt;endl;





cin%26gt;%26gt;scores;





if ( ( scores % 2) != 0 )


totalodd = totalodd + scores;


}
Reply:A second issue is that you need to store the highest value somewhere, maybe in a variable named "highest". After the first value gets read into "scores", assign that as the highest value, for later values you must compare to the previous highest:





if (counter == 1) // 1st value is highest by default


highest = scores;


else if (scores %26gt; highest) // later values get compared to previous highest


highest = scores; // if new value%26gt;previous highest, then make that the highest


Need help creating Loops for C++?

I have this code for temperature check im just a begginer on this don't blame me.


Our proffesor wont give us the code for loops.


ahhmm mainly after the prossess is done i would like to input whether i pres Y to try agian or N to shut down the program ahhm pls help! im a die hard on this thing here the code i've started with.








#include %26lt;iostream%26gt;


using namespace std;


int main ()


{


int temperature, pressure;


cout%26lt;%26lt; "Input temperature: \n";


cin%26gt;%26gt;temperature;





cout%26lt;%26lt; "Input pressure: \n";


cin%26gt;%26gt;pressure;





if (temperature%26gt;100 || pressure%26gt;200) {


cout%26lt;%26lt;"Warning" ; }





else {


cout%26lt;%26lt;"Okey" ; }





system ("PAUSE");


return 0;





}

Need help creating Loops for C++?
sorry dont know c++ but here's a shot..





#include %26lt;iostream%26gt;


using namespace std;


int main ()


{


string Continue;


Continue="y";


while(Continue=="y") {


int temperature, pressure;


cout%26lt;%26lt; "Input temperature: \n";


cin%26gt;%26gt;temperature;





cout%26lt;%26lt; "Input pressure: \n";


cin%26gt;%26gt;pressure;





if (temperature%26gt;100 || pressure%26gt;200) {


cout%26lt;%26lt;"Warning" ; }





else {


cout%26lt;%26lt;"Okey" ; }





system ("PAUSE");





return 0;





}


cout%26lt;%26lt; "Would you like to continue: \n";


cin%26gt;%26gt;Continue;


}
Reply:char answer;





cout%26lt;%26lt; "Would you like to test the temp: \n";


cin%26gt;%26gt;answer;


While (answer=='y' || answer==Y')


{


cout%26lt;%26lt; "Input temperature: \n";


cin%26gt;%26gt;temperature;


cout%26lt;%26lt; "Input pressure: \n";


cin%26gt;%26gt;pressure;


if (temperature%26gt;100 || pressure%26gt;200)


{ cout%26lt;%26lt;"Warning" ;


}


else


{


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


}


cout%26lt;%26lt; "Would you like to test the temp:again? \n";


cin%26gt;%26gt;answer;


}//ends while loop





Remember, the key to loops, whatever condition got you into it, has to get you out of it.
Reply:#include %26lt;iostream%26gt;


using namespace std;


int main ()


{


int temperature, pressure;


char try;


hell:


{


cout%26lt;%26lt; "Input temperature: \n";


cin%26gt;%26gt;temperature;





cout%26lt;%26lt; "Input pressure: \n";


cin%26gt;%26gt;pressure;





if (temperature%26gt;100 || pressure%26gt;200) {


cout%26lt;%26lt;"Warning" ; }





else {


cout%26lt;%26lt;"Okey" ; }


}


system ("PAUSE");


cout%26lt;%26lt;"Want to try again? Y/N";


cin%26gt;%26gt;try;


if(try=='Y')


{goto hell();}


return 0;





}











--i'm not sure bout the syntax but that's the flow...


Those familiar with STL in C++ Please Help?

If you guys have been following my last questions you will see that I have learned alot but still need some help. I have finally gotten my program to work with the vector of structs. Now I need to be able to show the name(s) of the highest scorer(s) and the name(s) of the lowest scorer(s). The names and the scores are stored inside the vector%26lt;Grades%26gt; Grade; vector of structs so Grade[0].names = "Mike" and Grade[0].scores = 90








Here is my program thus far it is error free as of now.





// In a header file


#ifndef GRADES_H


#define GRADES_H





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





struct Grades


{


string names;


int scores;


};





#endif

Those familiar with STL in C++ Please Help?
What's the question? By the way, the "Standard" Template Library is one of the main reasons why I don't think C++ is as beautiful as C. It seems there are as many different library implementations, and usages as there are companies willing to write compilers. Will your program work on every compiler, or just most of them?
Reply:Do the for loop, but do the swap inside for the highest score.


Say


int hightest=0


int lowest = 1000


int position=-1;//used to hold position of highest





for (int count = 0; count %26lt;= 4; count++)


{


if(VGrade[count].scores %26gt; highest)//first one will be


{


position = count;


highest=VGrade[count].scores


}





}


Now you know the position of who has the highest and using position for name of highest (or lowest)

covent garden

What is wrong with this c++ program??

I am trying to get this program to work but i can't - I am very new to this





#include %26lt;iostream%26gt;





using namespace std;





int Main()


{


const int seconds_per_minute = 60;


const int minutesPerHour = 60;





int timeInSeconds; // time that is input -- totally in seconds


int hours; // how many hours in time


int minutes; // how many minutes in time


int seconds; // how many seconds in time





cout %26lt;%26lt; "Enter the time in seconds only: " %26lt;%26lt; endl;


cin %26gt;%26gt; timeInSeconds;





seconds = timeInSeconds % seconds_per_minute;


minutes = timeInSeconds / seconds_per_minute % minutesPerHour;


hours = timeInSeconds / seconds_per_minute * seconds_per_minute;


// check the values of seconds, minutes, and hours


return 0;


}

What is wrong with this c++ program??
Well, for starters, 'Main' should be 'main'.
Reply:hours = timeInSeconds / seconds_per_minute * seconds_per_minute;





operations "/" and "*" has equal priority so they will be executed consequently, one after one: first, the time in seconds will be diveded by the number of seconds per minute ( i.e. we get number of minutes), then this result will be multiplied by the number of seconds per minute.
Reply:First you need to check if they have inputted over 60 seconds(1 minute) so you can calculate minutes. Do the same for hour, and check to see if you have at least 60 minutes to calculate hrs.





after "cin%26gt;%26gt; timeInSeconds" it should be:





if(timeInSeconds%26gt;=60) then //check to see if you have atleast 60 seconds


{


minuteSoFar = timeInSeconds / seconds_per_minute;


//minuteSoFarwill give you the number of minutes so far


//before calculating hours.Also since it is integer it wont give


//you a decimal value..e.g 70/60 will give you 1 not 1.167.





seconds=timeInSeconds%seconds_per_minute


// left over amount from mins, which is the seconds





if(minutesSoFar%26gt;=60)//check to see you have at least 60mins(1hr)


{


hours= minuteSoFar/minutesPerHour;


minutes=minuteSoFar%minutesPerHour;


}


else


hours = 0;


}


else


{


hours = 0;


minutes = 0;


}





cout %26lt;%26lt; "Hours = " %26lt;%26lt; hours %26lt;%26lt;endl;


cout %26lt;%26lt; "Minutes = " %26lt;%26lt; minutes %26lt;%26lt;endl;


cout %26lt;%26lt; "Seconds =" %26lt;%26lt; seconds %26lt;%26lt;endl;


return 0;





i think that should be right
Reply:It would be helpful to know the error if any this program is trying to generate. Obviously you are trying to get it to display the Values you have setup.





This is going to sound stupid, but the code looks fine with exception to the modulo calls. If your trying to use the remainder's for your values that might be where you are getting messed up (i.e. the % calls). If your trying to output your code definitely need to insert some cout's in there. This is pretty much all I can tell you from the pseudo code without knowing the error it generates. ALWAYS output your variables to see what is going on before committing it to a function.


What is wrong with this C++ program?

#include%26lt;iostream%26gt;


using namespace std;





int main()


{


int num, bigNum, power, count;





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


cin %26gt;%26gt; num;


cout %26lt;%26lt; "What power do you want it raised to? ";


cin %26gt;%26gt; power;


bigNum = num;


while (count++ %26lt; power);


bigNum *= num;


cout %26lt;%26lt; "The result is " %26lt;%26lt; bigNum %26lt;%26lt; endl;


return 0;


}

What is wrong with this C++ program?
count = 1 ; // probably count contains some junk value
Reply:Here are some of my few corrections with your program:


1.) Library header should have a ".h" extension


2.) avoid placing "int" in the main part of the program


3.) When you try to increment or decrement a variable, make sure that the variable already contains a value like 0 or 1.


4.)While loop's proper way of writing is while(condition){//statements}.


5.) A rule of thumb. Even if main() is a function, do not let main() return a value. Create another function to do the returning task.


6.) Put your "cout%26lt;%26lt;"The result is "%26lt;%26lt;bigNum%26lt;%26lt;endl;" outside the while statement so that it will not print the output while it is on the process mode. If you place the statement inside the while statement, the ways of reaching the result will be printed as well.





Here is my code (Extracted from your codes):





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





main()


{


int num, bigNum = 1, power, count = 0;





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


cin %26gt;%26gt; num;


cout %26lt;%26lt; "What power do you want it raised to? ";


cin %26gt;%26gt; power;


while (count %26lt; power)


{


bigNum *= num;


count++;


}


cout %26lt;%26lt; "The result is " %26lt;%26lt; bigNum %26lt;%26lt; endl;


}





Hope it helps!

email cards

Another C++ Question?

Sort and output an array of inputted characters, based on their number of occurrences (from highest to lowest). What's wrong with this code?





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





int main(void)


{


using namespace std;





char chars[]="abcdefghijklmnopqrstuvwxyz";


int i;


int count[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...





char inp;





cin%26gt;%26gt;inp;





while(inp !='.')


{


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


{


if(inp==chars[i])


count[i]++;


}


cin%26gt;%26gt;inp;


}





int swap;


char swapchar;





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


{


if (count[i] %26gt; count[i + 1])


{


swap = count[i];


count[i] = count[i + 1];


count[i + 1] = swap;





swapchar = chars[i];


chars[i] = chars[i + 1];


chars[i + 1] = swapchar;


}


}





cout%26lt;%26lt;"Character Count"%26lt;%26lt;endl;








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


{


if(count[i]!=0)


{


cout%26lt;%26lt;chars[i]%26lt;%26lt;" "%26lt;%26lt;count[i]%26lt;%26lt;endl;


}


}





system("pause");





return 0;


}

Another C++ Question?
You put your using statement inside main().
Reply:Well first of all your namespace position is incorrect... it should be after #include%26lt;fstream%26gt;, you don't need fstream since you are not doing any file streaming.





Second, check your braces... { and } i tried fixing your program and it doesnt work actually because of the errors... your swap or as we call it "Bubble sort" is ok... but change the limit from 26 to 25 since you'll be comparing the second to the last. Also, you'll have to put that in another loop since you need to do that 25 times again since you'll only be pushing one lowest number at a time... you should also try considering if there are equal times it appeared.





Note: I didn't fix it to work... i want you to handle that part. ^^, i'm just here to correct a few errors =)


I need help with this C++ program?

/CREDIT CARD PROGRAM


#include





using namespace std;





int main()


{


//TASK ONE: DECLARE A VARIABLE CALLED balance OF TYPE float.


float charges;


float credits;


float creditLimit;


char pause;





cout %26lt;%26lt; "Enter beginning balance (use -1 to end):";


//TASK TWO: WRITE STATEMENT TO READ KEYBOARD INFORMATION AND


//STORE VALUE IN THE VARIABLE balance.





while ( ) //TASK THREE: COMPLETE while SO THAT THE


//LOOP IS ENTERED ONLY IF


//balance IS NOT EQUAL TO -1.


{


cout %26lt;%26lt; "Enter total charges: ";


cin %26gt;%26gt; charges;





cout %26lt;%26lt; "Enter total credits: ";


cin %26gt;%26gt; credits;





cout %26lt;%26lt; "Enter credit limit: ";


cin %26gt;%26gt; creditLimit;


Theres more to it, but f someone could point me in the right direction on how to complete this part, I could probably use that to finish the rest

I need help with this C++ program?
#include %26lt;iostream%26gt;


using namespace std;





int main()


{


//task 1:


float balance;


float charges;


float credits;


float creditLimit;


char pause;





cout %26lt;%26lt; "Enter beginning balance (use -1 to end):";


//task 2


cin%26gt;%26gt;balance;





//task 3


while (balance != -1)


{


cout %26lt;%26lt; "Enter total charges: ";


cin %26gt;%26gt; charges;





cout %26lt;%26lt; "Enter total credits: ";


cin %26gt;%26gt; credits;





cout %26lt;%26lt; "Enter credit limit: ";


cin %26gt;%26gt; creditLimit;





/* Now make sure that you finish the rest of the program with a return 0; for the end of the main and to close your while loop and you will be fine. hope this helps


*/
Reply:homework? XD. Well i dont know if its part of your program but at the top your comment needs 2 slashes.





//Credit Card Program.





You arent including anything so you need





#include %26lt;iostream%26gt;





and I believe your while loop cant have the comments inbetween the bracket like that ... I havent tested so i dont know for sure ...





and other than that the code ERRORS are fixed.





Hope this helps ^_^


What is wrong with my c++ program?

#include %26lt;iostream%26gt;


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


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


using namespace std;





int main()


{


int guess, actual;





srand(rand());


actual = rand() % 10 + 1;





cout %26lt;%26lt; "Guess a number between 1 and 10: ";


cin %26gt;%26gt; guess;





if (guess = actual) cout %26lt;%26lt; "Congrats!!";


else if (guess /= actual) cout %26lt;%26lt; "Incorrect. The correct number is " %26lt;%26lt; actual %26lt;%26lt; ".";











return 0;








}





The program is supposed to generate a random number and determine whether your guess is right or not but every guess I enter is determined to be correct. What is wrong?

What is wrong with my c++ program?
You are using only one '=' in your condition statement rather than '=='. Essentially what is happening is you are assigning the value of actual to guess rather than comparing the values. That assignment operation returns a non 0 value, so the condition is evaluated as true





Change the line





if(guess = actual) ....





to





if(guess == actual) ...


I need help with a c++ program please?

Hey guys I have a program that I need to write and I have no idea how to do it:


this program has to prompt the user in a menu to encrypt a message, decrypt or quit.


I'm supposed to use functions in this program


This is what i am supposed to use without removing any parts, just adding things where needed.


#include%26lt;iostream%26gt;


using namespace std;





int menu();


void encrypt(int);


void decrypt();








int main(){





int choice;


int shift = 7; // default shift


choice = menu();


while (choice != 3){


if (choice == 1){


cout %26lt;%26lt; "Enter the 'shift' value: ";


cin %26gt;%26gt; shift;


encrypt(shift); }


else


decrypt();





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


choice = menu();


}


return 0;


}


I don't even know how to get started functions kind of confuse me


Can someone at least point me in the right direction?

I need help with a c++ program please?
From what I can see here, all the shell functions are already implemented.





You have:


int menu() which prompts the user to enter 1, 2 or 3.





And a while loop that quits if the user types in 3.


1 for encrypt() and 2 for decrypt().





However, where is the code for menu() encrypt() and decript()?


If you're not provided with the codes, then perhaps you need to implement these functions.





//psudo-C-code


int menu(){


char input; // User's input is stored here.


//cout %26lt;%26lt; "Please make a choice:" %26lt;%26lt; endl;


// cout " 1.encrypt"


// cout " 2.decrypt"


// cout " 3.quit"


cin %26gt;%26gt; input;


//convert the input (char) into int and return it.


//You can either use atoi(input) or you can do this:


// return (int)input - '0';


}





I am assuming that the 'Message' you were supposed to key in will be prompted for when the decrypt or encrypt function runs.





void decrypt(){


//prompt for the number sequences (encrypted message)


//Store them in a char array


//For each character in the char array, convert them to the character-number chart you provided.


//Print out the converted results.


}








/*You need to be more specific about the requirements for these functions however, there's no way i would know what 'shift' does. You might need to ask your instructor for more information if it's not provided toyou.*/





void encrypt(int){


//Prompt for a message


//Store message in char array


//Convert each char in the array to the encrypted numbers.


//Print out the encrypted message.


}
Reply:this program seems to be a based on cryptography. u have not mentioned the algorithms used in encrypting and decrypting since are many such methods to do. make sure u have one. Then write the code for each in c or C++. as here


void encrypt( int e )


{


// place ur code here


}

cheap flowers

Why this program loop infinitely? [C++]?

#include %26lt;iostream%26gt;


using namespace std;





int main()


{


int accNum, begin , charges, credits ,


limit;








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


cin%26gt;%26gt;accNum;


while (accNum !=-1)


{





cout%26lt;%26lt;"Beginning balance: ";


cin%26gt;%26gt;begin;


cout%26lt;%26lt;endl%26lt;%26lt;"Total charges: ";


cin%26gt;%26gt;charges;


cout%26lt;%26lt;endl%26lt;%26lt;"Total credits: ";


cin%26gt;%26gt;credits;


cout%26lt;%26lt;endl%26lt;%26lt;"Credit limit: ";


cin%26gt;%26gt;limit;


if (begin+charges-credits %26gt;limit){


cout%26lt;%26lt;"\t Calculating.."%26lt;%26lt;endl


%26lt;%26lt;"Account: "%26lt;%26lt;accNum;


cout%26lt;%26lt;"Credit limit: "%26lt;%26lt;limit


%26lt;%26lt;endl;


cout%26lt;%26lt;"Balace: "%26lt;%26lt;begin+charges-credits


%26lt;%26lt;endl;


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


}


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


cin%26gt;%26gt;accNum;


}


}

Why this program loop infinitely? [C++]?
There is nothing wrong with this program.


It only 'loops endlessly' when you input a non-number value.


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!


Newb C++ Problem i cannot solve, plz HELP beginner?

#include%26lt;iostream%26gt;


using namespace std;





int main ()


{


int x;


int y;





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


cin %26gt;%26gt; x ;





cout %26lt;%26lt; " Your Number is " %26lt;%26lt; x %26lt;%26lt; endl;


cout %26lt;%26lt; "Good, Now choose another: ";


cin %26gt;%26gt; y;


cout %26lt;%26lt; " the equation will be " %26lt;%26lt; y %26lt;%26lt; cout %26lt;%26lt; " plus " %26lt;%26lt; x %26lt;%26lt;endl;





system ("pause");


return 0 ;


}





it prints :





Enter number: 5


Your Number is 5


Good, Now choose another 9


the equation will be 90x4433c4 plus 5


Press any key to continue . . .








Now i want to know why does it show "90x4433c4" and not "9"

Newb C++ Problem i cannot solve, plz HELP beginner?
Though you did not mention what do u mean by equation; whether you want to add both numbers...





The problem I see is: remove the cout which is appearing after y. In shot remove "%26lt;%26lt; cout" which is appearing after y. Your statement should appear like this:





cout %26lt;%26lt; " the equation will be " %26lt;%26lt; y %26lt;%26lt; " plus " %26lt;%26lt; x %26lt;%26lt;endl;








And if u want to add x and y then you need to do like this





cout %26lt;%26lt; " the equation will be " %26lt;%26lt; y %26lt;%26lt; " plus " %26lt;%26lt; x %26lt;%26lt; "=" %26lt;%26lt; x + y;
Reply:The 9 prints correctly





the 0x4433c4 that follows it is the hexadecimal for of the cout statement, as you only need "cout" once, it is actualy outputting the cout, if that makes sense
Reply:Remove the %26lt;%26lt; cout in the middle of the line.


You are printing out the address to the cout method.
Reply:You get some expert help from http://expert.ccietutorial.com/
Reply:Hi


The Number which you see in the consol is the address of the cout object (because 'cout' is an object from the ostream class)


and you have to remove the 'cout' to get the right number





Another thing i see in our code


you have to initialized your attributes


int x=0;


Not to make problems in other times


Help c++ programing problem?

//load and save... i hope!!!


#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;


int main()


{


system ("color 2B");


int choice;


int number;





cout %26lt;%26lt; "hi.\n\n\nContinue:1\nNew:2\n\n\n";


cin %26gt;%26gt; choice;





if (choice==2)


{ cout %26lt;%26lt; "\n\nEnter number.";


cin %26gt;%26gt; number;





cout %26lt;%26lt; "Number stored";


}


if (choice==1)


{


cout %26lt;%26lt; "\n\n\nYour number is: ";


cout %26lt;%26lt; number;


}





system ("PAUSE");


return 0;


}





How do I make it to where when the user restarts the program it will display the number they entered before? everytime i try to load a number i entered it always says 49. plzz post





Ive made this post several times with no luck so someone plz post. Also, leave specific details on what I need to add or change. Even if you have to show me the source code that im suppose to have lol.

Help c++ programing problem?
You need to write the number to a file. You have the correct header to do this.. I just don't think you fully understand how to use it. for a full tutorial, go to http://www.cprogramming.com/tutorial/les...





Here's a program for you





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





using namespace std;





int main(){


system ("color 2B");


int choice;


char number[4];


ofstream thing("number.txt", ios::app);//will make file number.txt


ifstream read;


start:


cout %26lt;%26lt; "Continue:1\nNew:2\n";


cin %26gt;%26gt; choice;





if (choice == 1){


read.open("number.txt");


if (!read){


cout%26lt;%26lt;"We've encountered a problem.. I'm sorry\n";


system("pause");


}


while(read %26gt;%26gt; number){


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


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


read.close();


}


}


else if(choice == 2){


cout %26lt;%26lt; "\n\nEnter number.";


cin %26gt;%26gt; number;


thing %26lt;%26lt; number;


cout%26lt;%26lt;"Number stored";


thing.close();


}


else{


cout%26lt;%26lt;"Invalid choice";


goto start;


}


system("pause");


}








I use dev-c++, just in case this doesn't compile right for you.

baseball cards

What is wrong with this C++ program?

#include%26lt;iostream%26gt;


using namespace std;





int main()


{


int numCount, total;


double average;





cout %26lt;%26lt; "How many numbers do you want to average? ";


cin %26gt;%26gt; numCount;


for (int count = 0; count %26lt; numCount; count++)


{


int num;


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


cin %26gt;%26gt; num;


total += num;


}


average = total / numCount;


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


return 0;


}

What is wrong with this C++ program?
dude int total get initialized to garbage value..


so use


int numCount,total=0;


this should giv u the correct answer





#include%26lt;iostream%26gt;


using namespace std;





int main()


{


int numCount, total=0;


double average;





cout %26lt;%26lt; "How many numbers do you want to average? ";


cin %26gt;%26gt; numCount;


for (int count = 0; count %26lt; numCount; count++)


{


int num;


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


cin %26gt;%26gt; num;


total += num;


}


average = total / numCount;


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


return 0;


}
Reply:total/numCount is integer devided by integer wil result in fraction part truncated. Also all vaiables need to be initialized to 0.





Two Solutions


1. Use datatype casting: i.e., You can replace


average = total/numCount ;


with


average=(double)total / (double) numcount;





2. Initialize numcount and Total as double/float datatype


instead of integer.
Reply:It looks ok to me. The only thing I would suggest is initializing your variables to something so you know you don't have junk in them. So set numCount and total to 0 at the top and also set average to 0.0 and don't forget to set num = 0 in your for loop as well. I'm not sure exactly what the problem is or if there is one since you didn't mention a specific error.
Reply:Try placing the "int num;" outside of the for.





for total, make it "total = total + num;"





Remember to close everything, even "for" with a ";"





If this doesn't fix it, can you say what exactly the problem is when it runs?





It's been a long time since C++, sorry if I'm wrong.


I need help with a c++ program please?

im getting some errors in my program that i dont know how to fix help please


ill post the program first and then the errors





#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


using namespace std;


void tally(int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;...


void print(int, int, int, int);





int main() {





cout%26lt;%26lt;"CS-114 Ballot Counter"%26lt;%26lt;endl%26lt;%26lt;endl;


int p1,p2,vp1,vp2,s1,s2,t1,t2,j1,j...








cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Presidency:"%26lt;%26lt;endl;


print(1, 2, p1, p2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Vice Presidency:"%26lt;%26lt;endl;


print(3, 4, vp1, vp2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Secretary:"%26lt;%26lt;endl;


print(5, 6, s1, s2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Treasurer:"%26lt;%26lt;endl;


print(7, 8, t1, t2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Judge:"%26lt;%26lt;endl;


print(9, 10, j1, j2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Senator:"%26lt;%26lt;endl;


print(11, 12, sen1, sen2);





}

I need help with a c++ program please?
I have never used C++, but just looking at the code, like in mathematics, it looks like you my be missing some brackets- like "}}}}" for the other side of your program code for your variables int p1,p2,vp1,vp2,s1,s2,t1,t2,j1, j.., and so on. Just like in Excel, mathematics, or any other program, your variables, Boolean logic, and other definitions will not work unless what you plug into the formulas follow certain procedures like Multiplication, Division, Addition, and Subtraction. I believe what you have at the top is what is called the Pseudo code (which describes what the program should do so this is only relevant to other programmers who want to know what your program should do).
Reply:What compiler you using with? it didn't show the line number where the error is, that's hard for you and us to know where is the error located.
Reply:What language is this???
Reply:i'm sick of that, why not u ask with the teacher.


I need help with a c++ program please?

hey Im getting some errors that dont make sense to me and i dont know how to fix


ill post my code and then the errors


#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


using namespace std;


void tally(int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;...


void print(int, int, int, int);





int main() {





cout%26lt;%26lt;"CS-114 Ballot Counter"%26lt;%26lt;endl%26lt;%26lt;endl;


int p1,p2,vp1,vp2,s1,s2,t1,t2,j1,j2,sen1,sen...








cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Presidency:"%26lt;%26lt;endl;


print(1, 2, p1, p2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Vice Presidency:"%26lt;%26lt;endl;


print(3, 4, vp1, vp2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Secretary:"%26lt;%26lt;endl;


print(5, 6, s1, s2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Treasurer:"%26lt;%26lt;endl;


print(7, 8, t1, t2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Judge:"%26lt;%26lt;endl;


print(9, 10, j1, j2);





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Here's the race for the Senator:"%26lt;%26lt;endl;


print(11, 12, sen1, sen2);





}

I need help with a c++ program please?
What are the errors?


I need help with a c++ program please?

Ok I need to write a program that encrypts and decrypts entered.


It also has to take into account a "shift" value that changes the encryption/decryption output.


like say the value for k is 1, if you enter a shift value of 7 and ask for the program to encrypt k it should print out 8





Here is the program:





#include%26lt;iostream%26gt;


using namespace std;





int menu(){


cout%26lt;%26lt;"Press 1 to encrypt, 2 to decrypt, 3 to quit)"%26lt;%26lt;endl;


int x;


cin%26gt;%26gt;x;


return x;





}


void encrypt(char){


char letter;





cout%26lt;%26lt;"Enter a message to encrypt (! to quit)"%26lt;%26lt;endl;


cin%26gt;%26gt;letter;


while (letter!='!'){


if (letter=='k') cout%26lt;%26lt;"1 ";


followed by 26 more if statements for other letters





cin%26gt;%26gt;letter;


}


return;


}











void decrypt(){


cout%26lt;%26lt;"Enter a message to decrypt (0 to quit)"%26lt;%26lt;endl;


int code;


cin%26gt;%26gt;code;


while (code!=0){


if (code==1) cout%26lt;%26lt;"k";


Followed by 26 more if statements





(will continue in additional details)

I need help with a c++ program please?
looks like you haven't even used the shift value in your encrypt function. you can't use the shift variable defined in main() because it's out of scope in encrypt()





just change the encrypt function to encrypt(int s) -you don't need a char there- then before printing out add s to 1 like this:


if(letter=='k')


{


cout%26lt;%26lt;s+1


}


now you have both problems solved.


good luck and I hope this helped.





ps: since you have 26 options I suggest you use a case construct instead of so many if statements.
Reply:This scares me!!! I took C++ a fews years back and out teacher made us code everything in notebad. I hated that class, good luck because I don't have clue of what is wrong.
Reply:1) u have not included shift value in ur program.u can check it out.


2) to make functions encrypt(int),just replace the prototype and definition arguement type to int and also store them in int too in the function.

artificial flowers

Creating a simple menu in C++?

I want to create a very simple menu that one option to allow me to load a input file and another option to display the input file and the last option to quit the program.. Is there any resources that can help me with this?





I have this so far:





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;





using namespace std;





int main()


{


int l, d, q;


char ch;


ofstream outFile;


string outputFile;





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


cout %26lt;%26lt; "L Load from file";


cin %26gt;%26gt; ch;


cout %26lt;%26lt; endl;





outFile.open("sample.txt", ios::out);}





I compile it successfully but running it was kinda messed up (figured that anyway since it's not completely done).

Creating a simple menu in C++?
it is an example of implementng menu urs dont has any menu concept.








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


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





void main(void)


{


int num1, num2, operation, result;





clrscr();


printf("Enter a number: ");


scanf("%d", %26amp;num1);


printf("Enter a number: ");


scanf("%d", %26amp;num2);





printf("Indicate math operation\n[1:add; 2:sub; 3:mul; 4:div]: ");


scanf("%d", %26amp;operation);





switch(operation){


case 1:


result = num1 + num2;


break;


case 2:


result = num1 - num2;


break;


case 3:


result = num1 * num2;


break;


case 4:


result = num1 / num2;


break;


default:


result = 0;


}





printf("\nThe result is %d", result);


}


I want to create a c++ program which shows the proper divisors of a number n.Can you help me?

i have tried this program but it does not work:





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


int a1,b1,a2,b2;


cout %26lt;%26lt;"n= ";


cin %26gt;%26gt; n;


d=2;


x=n/2;


while ( d%26lt;=x )


{


int r;


r=n%d;


if(r=0)


{


cout %26lt;%26lt; "The proper divisors are " %26lt;%26lt; d;


}


d=d+1;


}





return 0;


}

I want to create a c++ program which shows the proper divisors of a number n.Can you help me?
your program is just fine. Good job!


Just a copule of things:


- You want to declare variables you are actually using (not a1,a2,b1,b2) - change the declaration line to


int w,d,xn;





- You want your "if (r=0)" statement look like "if (r==0)" or just if (!r)


'=0' is the asignment operation - it makes the value of r to be 0, and always evaulates to 0. To make a comparison, you want '=' to appear twice - r==0. Or, when comparing with 0 you can make a shortcut - 0 is the same as false, and everything else is true. So


if (!r) is quivalent to if (r==0), but shorter and safer (because it is not ambigous, and you can't mistake it for assignment be leaving out a '=' sign'





- Finally, you wand to add '%26lt;%26lt;endl' after 'd' in your cout statement - so that the divisors you find get printed one per line.





Logically, your program does the right thing. You got it right. Congratulations.





P.S. Do not use the program somebody gave you above. It has a logical error in it, unlike yours :-)
Reply:I've no clue about C++


Have you tried some programming forums?


Try http://rohitab.com/ - They do Programming, Making Viruses, Scripting %26amp; You have to read their rules! They're strict, but fair.


I'm on there as Nitrogen, lol.





Influx UK
Reply:Use the following program to know the divisors list.


# include %26lt;iostream%26gt;


int main()


{


int remainder, number, divisor, divisorcount = 0;


cout%26lt;%26lt;"Enter any number to know its divisors";


cin%26gt;%26gt;number;


divisor = number / 2;


while (divisor %26gt; 1)


{


remainder = number/divisor;


if (remainder == 0)


{


cout%26lt;%26lt;divisor%26lt;%26lt;" is a divisor"%26lt;%26lt;endl;


divisorcount ++;


}


divisor --;


}


cout%26lt;%26lt;"Total number of divisors " %26lt;%26lt; divisorcount;


}


I cannot compile my first C# programme. Where are the libraries located?

namespace.cs(8,4): error CS0117: 'System.Console' does not contain a definition


for 'Writeln'





--------------------------------------...


What does the above mean?


--------------------------------------...

I cannot compile my first C# programme. Where are the libraries located?
it means exactly what it says.


you failed to supply a required argument for a function/object


What's wrong with this C++ program?

#include %26lt;iostream%26gt;





using namespace std;





int main(int argc, char *argv)


{


cout %26lt;%26lt; "This will contain numbers 1-10:\n";





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


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





return 0;


}

What's wrong with this C++ program?
The only critical error is in the syntax of the


termination condition of the "for" loop. There's


a typo such that it only says:





    %26lt;= 10





and it should be:





    i %26lt;= 10





There's a technical (but in this case unimportant)


error in that the prototype for "main" should be:





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





Note that the second parameter is not a pointer


to char, but rather a pointer to array of char.





The repaired code looks like:








#include %26lt;iostream%26gt;





using namespace std;





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


{


   cout %26lt;%26lt; "This will contain numbers 1-10:\n";





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


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





   return 0;


}
Reply:where it says ''argc'' it should say ''arge''
Reply:You're missing the "i" before expression "%26lt;=10"





corrected:


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

800flowers.com

What is wrong with this C++ syntax?

#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;








void convert(double numberSize, double current, string typeOF);


int main()


{


double number;


char measurement;





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


cin %26gt;%26gt; number;


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


cin %26gt;%26gt; measurement;





switch(measurement)


{


case "inches":


convert(0.083 333 333, number, "inches");


}


system ("pause");





return 0;


}


void convert(double numberSize, double current, string typeOF)


{


cout %26lt;%26lt; "Type: " %26lt;%26lt; typeOF %26lt;%26lt;


endl %26lt;%26lt; "Size: " %26lt;%26lt; numberSize * current;


}

What is wrong with this C++ syntax?
It looks like your variable "measurement" should be a character array instead of char. Then you use cin.getline to read it in. Finally you cannot use a switch statement with strings, so you would use an if statement.





Example:


char measurement[128];


std::cin.getline( measurement, 128);





std::string compareString;


compareString = measurement;





if(compareString.compare("inches") == 0)


{


// do stuff


}
Reply:Haven't done much C++ before but these lines:





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


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





should be,





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


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





The nesting of quotes is wrong at the moment.
Reply:Paraphrasing the compiler error in g++, "Case labels must be able to be reduced to an integer constant". "inches" is an array of chars. Your compiler probably should have given you an error.





If you use the 'char' type for your case labels, e.g. 'i', than it will work, however this limits you to single-letter input. If you really want to use strings, you can use a hash or a map to get an integer value from your known strings. It looks as if you're only altering a double (numberSize), so you can make a string to double map that will return the desired constant when you feed it a string, and scrap the switch. Something like:





struct CompStruct


{


bool operator()( const char* s1, const char* s2 ) const


{


return strcmp( s1, s2 ) %26lt; 0;


}


};





//inside main():





map%26lt;const char*, double, CompStruct%26gt; numberSizes;


numberSizes["inches"] = 0.083333333;


numberSizes["something"] = 0.123456789;


// etc.





string stringFromUser;


cin %26gt;%26gt; stringFromUser;


convert(numberSizes[stringFromUser], number, stringFromUser);








The syntax might be off, but I suppose it will work. Don't forget your error handling in case the key is not found.