Friday, July 31, 2009

C++ Programming Trouble?

I started the problem but I am stock. I do not know what to do. Please help!





Write a program that asks for two positive fractions, displays the fractions, and returns both the exact sum and


the exact product of the fractions in lowest terms.


To display a fraction “a / b”, where a and b are the numerator and the denominator, you may use a cout statement


that uses ...%26lt;%26lt; a %26lt;%26lt;" / " %26lt;%26lt; b %26lt;%26lt; ...








#include %26lt;iostream%26gt;


using namespace std;





struct frac{int numer, denom;};





frac f_add( frac x, frac y );





int main( ){


frac r, s, sum;


cout %26lt;%26lt; "Enter the numerator and the denominator of the first positive fraction separated by a space=%26gt; " %26lt;%26lt; endl;


cin %26gt;%26gt; r.numer %26gt;%26gt; r.denom;


cout %26lt;%26lt; "Enter the numerator and the denominator of the second positive fraction separate by a space=%26gt; " %26lt;%26lt; endl;


cin %26gt;%26gt; s.numer %26gt;%26gt; s.denom;


sum = f_add(r,s);


cout %26lt;%26lt; "The sum of " %26lt;%26lt; r.numer %26lt;%26lt;"/" %26lt;%26lt; r.denom %26lt;%26lt; " and "%26lt;%26lt; s.numer %26lt;%26lt;"/" %26lt;%26lt; s.denom %26lt;%26lt;" in lowest term is " %26lt;%26lt; sum.numer %26lt;%26lt;"/" %26lt;%26lt; sum.denom %26lt;%26lt;".\n";


system ("Pause");


return 0;


}





frac f_add(frac x, frac y){





}

C++ Programming Trouble?
It seems you were given the template of the program, now you have to fill in the f_add function that takes two frac structures as input (x and y) and returns the sum.





Within f_add you have x.numer, x.denom and y.numer, y.denom. If you were to *multiply* x and y, them, you'd just do:





frac result;


result.numer = x.numer * y.numer;


result.denom = x.denom * y.denom;


return result;





Of course, you have to add them, which is just a bit harder (just remember how to add fractions), I'll let you do it hoping you get the idea.

tropical flowers

C++ multiplying 2d 3x3 matrix arrays in a loop?

How do I multiply each element of the matrix, say by 5, to display in output code?





#include %26lt;iostream%26gt;


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


#include %26lt;string%26gt;


using namespace std;








char quit;





int main( )


{


//declaring the 2d matrix arrays





float matrixOne[3][3];


float matrixTwo[3][3];








cout %26lt;%26lt; "Week 5 Assignment, A-5B of two 2d 3x3 matrixes by DR. " %26lt;%26lt;endl;





//*************assigning numbers to the first matrix*********


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


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


{


cout %26lt;%26lt; "Enter value for row " %26lt;%26lt;row+1 %26lt;%26lt; " column " %26lt;%26lt;column+1 %26lt;%26lt; ": " %26lt;%26lt; endl;


cin %26gt;%26gt; matrixOne[row][column];


}


//************************************...





//calculation goes here ******





//***********





//*********outputting final matrix ***********


int row, column;





for (row = 0; row %26lt; 3; row++)


{


for (column = 0; column %26lt; 3; column++)


cout %26lt;%26lt; matrixOne[row][column];


cout %26lt;%26lt; endl;


}


//************************************...








cout %26lt;%26lt;"Type quit to exit " %26lt;%26lt; endl;


cin%26gt;%26gt;quit;

C++ multiplying 2d 3x3 matrix arrays in a loop?
well...I feel like i am doing your hw for you...but since i'm a bit rusty on my c++, I'm going to...pseudo this for you...the calculation section anyways. There are different ways you can do this, but off the top of my head, I thought of 2 similar ways





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


1) take each input while its happening and multiply it right there before you put it in the matrix. example: after the cin%26gt;%26gt;matrixOne[row]column]; line, put something like matrixOne[row][column] = matrixOne[row][column] x 5;


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


2) if you need the actual calculations in the calculation section, you would need to do the whole nested loop again, [for (int row....) for (int column...) and in the nested loop, do the whole matrixOne[row][column] = matrixOne[row][column] x 5; line again.


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





And just a side note, it doesn't really really matter, but if you were to turn this program in as is, you might want to look at the following issues:





1) float matrixOne[3][3]; and float matrixTwo[3][3]; if you are putting in [3][3] in place of row and column, since row and column are both int, the declaration of float isn't necessary, because those values will never be a non whole number. Float takes up more memory in a program, and in bigger programs, you want to cut down on the memory space as much as possible.





2) If you are only going to use the matrixOne[3][3] and matrixTwo[3][3] for the row and column, you might want to consider coding it like this:


int row = 3;


int column = 3;


float matrixOne[row][column];


float matrixTwo[row][column];





that way, if you have to change all the number of rows in the whole program (changing your matrix size), you wouldn't have to go through each line that says float matrixOne[3][3]; and change them, you could just change the line that says int row = 3;.





3) putting float matrix[3][3] is declaring 4 spaces in memory for each row and column (you have 0, 1, 2, 3) and in the program, you only fill up 3 of those spaces with value. - for (int row = 0; row %26lt; 3; row++) notice the row %26lt; 3, and not row %26lt;=3.





4) instead of putting int row and int column in your for loop, and then later in your output, you should just put int once on top, like a global declaration. Besides, wont this give you an error like declaring it twice? I dont remember. It will help later one when you learn about functions and classes.





finally


5) cout type quit to exit, and cin quit. quit is a char, meaning it just takes one letter. so if you type quit, anything inputted after the first character is pointless. If you want to use char for quit, you can just tell the user to type q to exit.





Good luck with your programming!
Reply:hello friend press F7(function key) to trace the path of the program!


Whats wrong with this C++ program??????

#include %26lt;iostream%26gt;


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





int();


{


std::cout %26lt;%26lt; "add two numbers....The first one will be subtracted from the second" %26lt;%26lt; std::endl;


int v1, v2;


std::cout %26lt;%26lt; "The no: to be sbtracted" %26lt;%26lt; std::endl;


std::cin %26gt;%26gt; v1;


std::cout %26lt;%26lt;"The no: to subtract from" %26lt;%26lt; std::endl;


std::cin %26gt;%26gt; v2;


std::cout %26lt;%26lt;"The difference between " %26lt;%26lt; v1 %26lt;%26lt;"and" %26lt;%26lt; v2 %26lt;%26lt; "is" %26lt;%26lt; v2-v1 %26lt;%26lt; std::endl;





return 0;


}





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





Please re do the program if you find the error.


Its a subtraction

Whats wrong with this C++ program??????
I think the first line has to be 'int main()'





ie add 'main' and lose the terminating ';'. The bit between the braces is defining 'main', so we don't want to terminate before we reach it!
Reply:hahaha simple mistake Report It



C++ Question?

I have a vector of structs. The struct contains a string and int variable.





I take in the information like this:





while(check != true)


{


cout %26lt;%26lt; "Name: ";


cin %26gt;%26gt; DataInfo.info;





if(DataInfo.info == "-99")


check = true;





cout %26lt;%26lt; "Phone Number: ";


cin %26gt;%26gt; DataInfo.data;





if(DataInfo.data == -99)


check = true;





Vector.push_back(DataInfo);





}








Ok simple right. Whats the best way to print the contents??





I tried the copy function from the %26lt;algorithm%26gt; header file but it wont work on vectors of structs.





Any Ideas?

C++ Question?
for(int i=0; Vector.size(); i++)


cout%26lt;%26lt; Vector[i].info %26lt;%26lt; "-" %26lt;%26lt; Vector[i].data %26lt;%26lt;endl;
Reply:TRY


system.out.println(" " )


Need help with code (C++)?

ok here it is... my problem is this...


I can type in the name to the movie which is two words ( Death Grip)


but then when i want to put the adult tickets in its always accompanied by children too...


whats weird is if my movie name is one name like (Death)


then i can seperately imput adults and children.


WHAT DO I DO? heres my code. dont just tell me...


please acually write it out for me.... im learning still





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;


string name[50];


string adult;


string child;


cout %26lt;%26lt; "Enter the movie's Name: ";


cin %26gt;%26gt; name[50];


cout %26lt;%26lt; "Enter the number of adult tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; adult;


cout %26lt;%26lt; "Enter the number of child tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; child;


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


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


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


cout %26lt;%26lt; " INCOME STATEMENT" %26lt;%26lt; endl;


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


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


cout %26lt;%26lt; "Movie Name: " "Death Grip" %26lt;%26lt; endl;


cout %26lt;%26lt; "Adult Tickets Sold: " "382" %26lt;%26lt; endl;


cout %26lt;%26lt; "Child Tickets Sold: " "127" %26lt;%26lt; endl;


cout %26lt;%26lt; "Gross Box Office Profit: ""$" "2673.00" %26lt;%26lt; endl;


cout %26lt;%26lt; "Net Box Office Profit: ""$" "534.60" %26lt;%26lt; endl;


cout %26lt;%26lt; "Amount Paid To Distributer: ""$" "2138.40" %26lt;%26lt; endl;





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


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


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


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

















system("PAUSE");


return EXIT_SUCCESS;


}

Need help with code (C++)?
umm..





string name[50] isn't an array so just make it





string name





I think you got that confused with char arrays which would be





char name[50]





also you should add





const double adultTicketPrice





const double childTicketPrice
Reply:Change:


string name[50];


string adult;


string child;


cout %26lt;%26lt; "Enter the movie's Name: ";


cin %26gt;%26gt; name[50];


cout %26lt;%26lt; "Enter the number of adult tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; adult;


cout %26lt;%26lt; "Enter the number of child tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; child;





To this:


string name;


int adult, child;


cout %26lt;%26lt; "Enter the movie's Name: ";


getline(cin, name);


cout %26lt;%26lt; "Enter the number of adult tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; adult;


cout %26lt;%26lt; "Enter the number of child tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; child;
Reply:The guy above is right, but he's missing the point.





A space counts as a separator. So if you put in two words ("Death grip"), then "death" goes into name and "grip" goes into adult. Then whatever you thought you put into adult goes into child and then you're done with inputs. To fix this, read the whole line into the string like so.





Replace the string name[50] and the cin%26gt;%26gt;name[50] with this:





string name;


getline(cin,name);











BTW this section of code will output the same thing everytime:





cout %26lt;%26lt; "Movie Name: " "Death Grip" %26lt;%26lt; endl;


cout %26lt;%26lt; "Adult Tickets Sold: " "382" %26lt;%26lt; endl;


cout %26lt;%26lt; "Child Tickets Sold: " "127" %26lt;%26lt; endl;


cout %26lt;%26lt; "Gross Box Office Profit: ""$" "2673.00" %26lt;%26lt; endl;


cout %26lt;%26lt; "Net Box Office Profit: ""$" "534.60" %26lt;%26lt; endl;


cout %26lt;%26lt; "Amount Paid To Distributer: ""$" "2138.40" %26lt;%26lt; endl;





I think you wanted to write a program to output whatever you inputted. Try this:





cout %26lt;%26lt; "Movie Name: "%26lt;%26lt;name%26lt;%26lt; endl;


cout %26lt;%26lt; "Adult Tickets Sold: "%26lt;%26lt;adult %26lt;%26lt; endl;


cout %26lt;%26lt; "Child Tickets Sold: "%26lt;%26lt;child%26lt;%26lt; endl;





note that I replace the specific values with the variable name instead. For the other stuff outputted (like gross sales), I can't tell you how to do that because I don't know all the info, but I trust you can do it.

sound cards

Anyone, kind enough to help with a C++ parallel array?

I need to display the price and quantity of the item whose ID is entered by the user. Below is what I have but it only displays some number I have no idea where it is coming from. -858993460 for both prices quantities





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using std::string;


using std::cout;


using std::cin;


using std::endl;





int main()


{


//cin %26gt;%26gt;


//declare arrays


string id[5] = {"10", "14", "34", "45", "78"};


int prices[5] = {125, 600, 250, 350, 225};


int quantities[5] = {5, 3, 9, 10, 2};


string searchForID = "";





cout %26lt;%26lt; "Enter Product ID: ";


getline(cin, searchForID);





while (searchForID != "5")


{


int y = 0; //keeps track of array subscripts


while (y %26lt; 5 %26amp;%26amp; id[y] != searchForID)


y = y + 1;





if (y %26lt;= 5)


cout %26lt;%26lt; "Prices: $ " %26lt;%26lt; prices[y] %26lt;%26lt; endl;


cout %26lt;%26lt; "Quanty: $ " %26lt;%26lt; quantities[y] %26lt;%26lt; endl;








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


getline (cin, searchForID);





}





return 0;


} //end of main function

Anyone, kind enough to help with a C++ parallel array?
#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using std::string;


using std::cout;


using std::cin;


using std::endl;





int main()


{


//cin %26gt;%26gt;


//declare arrays


string id[5] = {"10", "14", "34", "45", "78"};


int prices[5] = {125, 600, 250, 350, 225};


int quantities[5] = {5, 3, 9, 10, 2};


string searchForID = "";





cout %26lt;%26lt; "Enter Product ID: ";


getline(cin, searchForID);





while (searchForID != "5")


{


int y = 0; //keeps track of array subscripts


while (y %26lt; 5 %26amp;%26amp; id[y] != searchForID)


%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;


wats this loop for


%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;


y = y + 1;


.........................................


after this while loop terminates y=5


so


.........................................





if (y %26lt;= 5)


cout %26lt;%26lt; "Prices: $ " %26lt;%26lt; prices[y] %26lt;%26lt; endl;


cout %26lt;%26lt; "Quanty: $ " %26lt;%26lt; quantities[y] %26lt;%26lt; endl;


.........................................


price[5] and qualities [5] are displayed which are garbage values


.........................................





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


getline (cin, searchForID);


.........................................


and wats this for


%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;%26gt;


}





return 0;


} //end of main function


C++ trouble?

I am having trouble to simplify the answer.


using namespace std;


int main(){


double dblA, dblB, dblC, dblD, dblproductN, dblproductD,dblsumN,dblsumD, dblGCF, dblsimplifyNsum, dblsimplifyDsum;


double dblsimplifyNproduct, dblsimplifySproduct;


int M,N;


int R=M%N;


while(R!=0)


{M=N;


N=R;


R=M%N;}





{


cout%26lt;%26lt;"Enter the numerator and the denomenator of the first positive fraction separated by a space=%26gt;"%26lt;%26lt;endl;


cin%26gt;%26gt;dblA%26gt;%26gt;dblB;


cout%26lt;%26lt;"Enter the numerator and the denaminator of the second positive fraction separated by a space=%26gt;"%26lt;%26lt;endl;


cin%26gt;%26gt;dblC%26gt;%26gt;dblD;


dblproductN =(dblA*dblC);


dblproductD =(dblB*dblD);


dblsumN = (dblA*dblD)+(dblC*dblB);


//dblGCF = N;


//dblsimplifyNsum= (dblsumN)/(dblGCF);


//dblsimplifyDsum= (dblproductD)/(dblGCF);


//dblsimplifyNproduct= (dblproductN) / (dblGCF);


//dblsimplifySproduct = (dblproductD) / (dblGCF);


cout%26lt;%26lt;"the sum of the fractions is" %26lt;%26lt;dblsu

C++ trouble?
http://en.wikipedia.org/wiki/Euclidean_a...


http://en.wikipedia.org/wiki/Binary_GCD_...


C++ program help!?

here is my code :





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int temp;





int main()


{


int numbers[5];


int counter;


char list[6][16];








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





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


{


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


}





cout %26lt;%26lt; endl;








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





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





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


cout %26lt;%26lt; endl;








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


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


{


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


}





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

















return 0;


}





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


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

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





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





in a for loop like you have done before.





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


C ++ geline() does not ignore leading whitespaces. How do you overcome this problem?

the input data: 0 12123-13123\n


code: cin %26gt;%26gt; num;


getline(cin, numbers);





num is an int and numbers is a string.


but numbers= 12123-13123


there is a whitespace b4 1.





How do you get rid of it?





Thank you!

C ++ geline() does not ignore leading whitespaces. How do you overcome this problem?
The code is wrong. It's actually





"cin.getline(...,...);" AND NOT "getline(cin,...);"





And more I din't understand what you said. The only way to get rid of leading spaces (What do you mean by whitespaces?) is to run a loop checking this and if a space was given then to again accept string from user. So the modified program would be like this:





/* uGetline.cpp */


/* To understand the use of getline */


/* NOTE:- This program uses old Borland C++ Compiler */


/* Some statements have to be changed */


/* Read - Only */


/* By Senthil */





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


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





char whtSp(char);


void main()


{


int num;


char numbers[150];


clrscr();





cout%26lt;%26lt;"Enter any number (within 32000) : ";


cin%26gt;%26gt;num;


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


numbers = whtSp();





do


{


cout%26lt;%26lt;"\nError! Please do not have a space in front!!!\n";


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


numbers = whtSp();


}while(numbers[0] != ' ')





clrscr();


cout%26lt;%26lt;"Value stored in int : "%26lt;%26lt;num;


cout%26lt;%26lt;"\nValue stored in char : "%26lt;%26lt;numbers;


getch();


}
Reply:none

liama-song

Need more help with c++ program?

ok i wrote an encryption program that reads in letters and prints out numbers and it works, but it doesnt work right


heres what i have:





int option;


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


cin%26gt;%26gt;option;


while (option!=3){


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


char letter;


cin%26gt;%26gt;letter;


while (letter!='!'){


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


then 26 more ifs for each other letter


cin%26gt;%26gt;letter;


}


}


for some reason it keeps printing out all of the numbers for each letter i enter


im not sure how to do it right

Need more help with c++ program?
you are doing an assignment in your if instead of a comparison.





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





Should be





if (letter=='k') cout%26lt;%26lt;"1 ";
Reply:From your program:





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





You need:





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





One '=' sets letter to 'k'





There's a better way of doing this.... Since you're converting a-z to 1-26 you can subtract 'a' from each character:





letter -= 'a' + 1;





Of course, if it's a capital letter you want to do:





letter -= 'A' + 1;
Reply:I used to have a similar problem until I started using switch case structures.


So, instead of all the if statements use a switch case structure with a number for each letter.


Note: In the first cout%26lt;%26lt; it is wise to notify the user that using ! will end the encryption loop.


C++ array?

#include %26lt;string%26gt;


#include %26lt;iostream%26gt;





using std::cout;


using std::cin;


using std::endl;


using std ::string;





int main ()


{





string numberMonth[12]= {"Janurary","Feburary","March","April","...


string flowerOfmonth [12]={" "};


flowerOfmonth[0]="Carnation";


flowerOfmonth[1]="Violet";


flowerOfmonth[2]="Daffodile";


flowerOfmonth[3]="Daisy";


flowerOfmonth[4]="Lily-of-the-Valley";


flowerOfmonth[5]="Rose";


flowerOfmonth[6]="Water Lily";


flowerOfmonth[7]="Gladiolus";


flowerOfmonth[8]="Aster";


flowerOfmonth[9]="Cosmos";


flowerOfmonth[10]="Chrysanthemum";


flowerOfmonth[11]="Narcissus";





//get number of month


cout %26lt;%26lt; "Enter month (1-12) :" %26lt;%26lt; endl;


cin %26gt;%26gt;numberMonth;


if (month %26gt;= 1 %26amp;%26amp; month %26lt;= 12)


cout %26lt;%26lt; flowerOfmonth[numberMonth - 1] %26lt;%26lt; endl;


//else


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


//end if


//end display salary





return 0;


} //end of main function








why cant i get this to work..thanks

C++ array?
You are expecting users to enter NUMERIC representation of the months. The wording of the months is NEVER used. So, numberMonths array definition is not needed.





Define numberMonths as an INTEGER.





Look what exactly you are doing with the numberMonth variable! It's an index for an array. Yet, you defined it as string.
Reply:try to chaneg this line


string flowerOfmonth [12]={" "};


to


string flowerOfmonth [12];


OR


initialize the second array as you have done with the first one


string flowerOfmonth = {"Carnation", "Violet", "Daffodile", ... }


I'm studying C++, I'm trying to declare hours as an integer & pay & wages as a float. How do I do this?

Also write assignment statement: currently I have this


cout %26lt;%26lt; endl ;


cout %26lt;%26lt; "Number of hours worked during"


%26lt;%26lt; " the week (integer) = " ;


cin %26gt;%26gt; hours_worked ;


// read in the pay rate


cout %26lt;%26lt; "Weekly pay rate (specify two digits "


%26lt;%26lt; "after the decimal point) = " ;


cin %26gt;%26gt; pay_rate ;


// compute wages


write assignment statement to compute wages ;

I'm studying C++, I'm trying to declare hours as an integer %26amp; pay %26amp; wages as a float. How do I do this?
wages= float(hours_worked) * pay_rates ;





this is the statement for ur program to compute wages
Reply:float total_pay;


int hours_worked;


float pay_rate;





// Your code





total_pay = (float)hours_worked * pay_rate


Programming issues with C++...please help?

For those who remember, this is the function I'm having problems with:





bool in_range(int val, int min, int max)


{


bool ans;


int nscores;


while ((val %26gt;= min) %26amp;%26amp; (val %26lt;= max))


{


cout %26lt;%26lt; "Please enter exam score " %26lt;%26lt; nscores %26lt;%26lt; " : ";


cin %26gt;%26gt; val;


if ((val %26lt; min) || (val %26gt; max))


{


int y = 1;


int n = 0;


cout %26lt;%26lt; endl %26lt;%26lt; "Score out of range!" %26lt;%26lt; endl %26lt;%26lt; endl;


cout %26lt;%26lt; "Do you wish to re-enter score number " %26lt;%26lt; nscores %26lt;%26lt; " (y | n) : ";


cin %26gt;%26gt; ans;


if (ans == y)


return 1;


if (ans == n)


{


return 0;


}


}


nscores = nscores + 1;





}


}





This is the part that is giving me issues. I have the right variables set and all. If you need a more in-depth look as to what this is doing, please use this link:





http://www.cs.uwm.edu/~cs201/semester/as...





The program is #12.

Programming issues with C++...please help?
You are out of spec. The specs call for the loop to keep accepting input then check for range. Only when the input is out of range that you ask if they want to re-enter or quit to the report.





Your program (once it gets past while ((val %26gt;= min) %26amp;%26amp; (val %26lt;= max)) ) will loop until invalid input is given. As this is coursework, I will only give pseudocode - the rest is up to you.





functionX (min, max)


{


loopagain=true;


while(loopagain)


{


displayinstructions();


// tell them to enter numbers, and


//enter Q to quit or something like that


if(checkifnumeric()==true)


{


if(checkifinrange()==true)


{


addToReport();


loopAgain();


}


else


{


displayInstructionsAndLoopAgainOrExit(...


//this is where you tell user that input is invalid


//and ask for valid input (a number in range or


//Q to quit)


}


}


else


{


if(checkifQ()==true)


{


gotoReport();


}


else


{


displayInstructionsAndLoopAgainOrExit(...


//this is where you tell user that input is invalid


//and ask for valid input (a number in range or


//Q to quit)


}


}


}


}
Reply:Well, after a quick look at your code snippet:





-You shouldn't allocate variables within an IF statement. You are allocating the 'y' and 'n' variables in a IF statement, which is within the WHILE loop. Allocate your variables outside of main() if you want them to be global. If you want to allocate local variables, then allocate them at the start of the procedure.


-Your 'ans' variable would be better off as a char. Cout and cin prints and inputs a variable based on the data type you are passing to it. In your 'cin %26gt;%26gt; ans' line, you want the user to input a character (y/n), so allocate 'ans' as a char. Your If statement would have to be modified to something like this: if (ans=='y')


-You can do some more idiot-proofing with the code that checks if the user pressed 'y' or 'n'.


For example, you could write something like this:





if (ans=='y')


return 1;


return 0;





If the user pressed 'n' or any other key, then the program will go to the 'return 0;' line.
Reply:Please clarify your issues, compiling error, runtime error or designing error?
Reply:you never initialize nscores, so when you output it the first time, you will get garbage.


the only way to exit the loop is to enter a invalid score and answer "n". if I read it right you need to add a return 0; after nscores = nscores + 1 line.

garden state

Help with my c++ program running buy 1 debug error?

Ok i have the function running but i need to make it say to use periods between website address if it doesn't str.find(".") or str.rfind("."). I put an else statement to say a string if the first if doesn't get accepted but it comes with a debug error if no periods are entered in cin. heres the function.





//Najib Saliba


//February 8,2008


//String Fling (reverses your website input)


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;





string reverse(string str)


{


string problem = "Please use periods between address";


int pos = str.find(".");


int pos2 = str.rfind(".");


if (str.find(pos)%26amp;%26amp;str.find(pos2))


return (str.substr(pos2+1, str.length()) + str.substr(pos, pos2-2) + str.substr(0, pos));


else


return problem;


}





int main()


{


string str;


cout %26lt;%26lt;"Enter a web adress starting with www" %26lt;%26lt;endl %26lt;%26lt;"This program will automatically reverse your input" %26lt;%26lt;endl;


getline(cin, str);


cout %26lt;%26lt;reverse(str) %26lt;%26lt;endl;


return 0;


}

Help with my c++ program running buy 1 debug error?
You are doing to many "finds". You already did the finds when you initialized pos and pos2. In the "if" statement just make sure they found something.





string reverse(string str)


{


string problem = "Please use periods between address";





int pos = str.find(".");


int pos2 = str.rfind(".");





if ((pos != string::npos)


%26amp;%26amp; (pos2 != string::npos))


return (str.substr(pos2+1, str.length()) + str.substr(pos, pos2-2) + str.substr(0, pos));


else


return problem;


}
Reply:If there is no period in the address, the find and rfind methods will return the str::npos value, which is not an integer or boolean value.





Instead of


if (str.find(".")%26amp;%26amp;str.find(".")...





You want to use something like





if ( (str.find("."))!= string::npos ) %26amp;%26amp; (str.rfind("."))!= string::npos ) )





I don't have a compiler handy so I may have made a parentheses/syntax error but I think that that is the correct logic.


How do I make it so this C++ program won't go into an infinite loop?

I'm not used to using character values in my loops. For some reason it goes a little while. It may not be infinite, I never waited long.





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





using namespace std;





char builder_name[35];


char choice;





void add_builder()


{





while(choice != 'N' || choice != 'n')


{





ofstream builders;


builders.open ("builders.txt", ios::app);





cout %26lt;%26lt; " Enter the name of a builder: ";


cin.get(builder_name, 35);


cin.ignore();





builders %26lt;%26lt; builder_name %26lt;%26lt; endl;





builders.close();





cout %26lt;%26lt; " Would you like to add another builder? (enter (Y) or (N): ";


cin %26gt;%26gt; choice;





};





}





int main ()


{





add_builder();





return 0;





}

How do I make it so this C++ program won't go into an infinite loop?
while(choice != 'N' || choice !='n')


In this line and (%26amp;%26amp;) should be used instead of or(||).


Because if or( || ) is used, atleast one condition will be true for any input (n or N). so loop will go infinite. Hence we should use and(%26amp;%26amp;) to make the loop to terminate for either of the input n or N.


Semicolon should not be used at end of while loop.
Reply:Change the line:


while(choice != 'N' || choice != 'n')


Into:


while(choice != 'N' %26amp;%26amp; choice != 'n')
Reply:Here's your problem - while(choice != 'N' || choice != 'n').


It's that ol' debbil double negative, in a different context. As long as choice isn't both N and n, it loops. If choice ==N, choice !=n is true and vice versa.


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

// bla bla


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


using namespace std;


int main()





{





int seconds;


double distance;


int choice;





const double CarbonDioxide = 258.0;


const double Air = 331.5;


const double Helium = 972.0;


const double Hydrogen = 1270.0;





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


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


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


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


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


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


cin %26gt;%26gt; choice;








if (choice == 1)


{


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


cin %26gt;%26gt; seconds;


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





{


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


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


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


}


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


distance = seconds * CarbonDioxide;


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


}


else if (choice == 2)


{


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


cin %26gt;%26gt; seconds;


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


{


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

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


distance = seconds * CarbonDioxide;


gets executed only if this condition evaluates to true:


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





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





A quick solution to the problem would be to replace


this:


double distance;


with this:


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


Ten points for c++ help?

So I have this program but I need to change it so that there is no std. I try to change it myself but then I alter the program too much and the code does not work anymore. I need someone to change so that there is no std, cout, cin, etc. Instead it has to be printf, getline, getinteger, etc. Please help, I reeeally need it.


#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;


#include %26lt;string%26gt;





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


{


std::string str;


std::cin%26gt;%26gt; str;


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


{


if ( ((str[i]%26gt;='a')%26amp;%26amp;(str[i]%26lt;='z')) || ((str[i]%26gt;='A')%26amp;%26amp;(str[i]%26lt;='Z')) )


{


std::cout%26lt;%26lt;str[i];


}


}


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


return 0;


}

Ten points for c++ help?
You need some experts experience to your programming %26amp; project. So you can search from


http://expert.freshbloger.com/
Reply:Add the line


using std::string;


after your last include.








#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;


#include %26lt;string%26gt;


using std::string;





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


{


...

funeral flowers

Help with my C++ program please!!?

this is the error i am getting and don't how to fix it: cannot convert parameter 3 from 'const double' to 'double %26amp;'


this is my code:


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::setprecision;


using std::fixed;





//function prototypes


void getInput(double %26amp;);


void calcBonus(double, double, double %26amp;);


void displayBonus(double);





int main()


{


//declare constant and variables


const double RATE = .1;


double sales = 0.0;


double bonus = 0.0;





//call funtions to get input


//call functions to calculate and display bonus amount


getInput(sales);


calcBonus(sales, bonus, RATE);


displayBonus(bonus);





//display output item


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





return 0;


} //end of main function





//*****function definitions*****


void getInput(double %26amp;sales)


{


//enter input items


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


cin%26gt;%26gt;sales;


}//end of getInput function

Help with my C++ program please!!?
The problem is that your declaration of and the definition for "calcBonus" do not match up. Your declaration indicates that the third parameter is a non-const reference, yet you pass in a const. You should change the declaration of "calcBonus" to match that of your definition, and that should fix everything.





ASIDE:


It is common in C to use "output parameters" (i.e., parameters which are reference types) for reporting results. However, it is generally preferred among C/C++ programmers for parameters to be "input", only, and for the results to be given through the function's return type.





That is, it would be preferrable to use:





inline double calcBonus(double sales, double RATE)


{


return sales * RATE;


}





Note that I also declared the function "inline", because it would be a waste to create a new stack frame for such a simple multiplication operation. Also, I used "double" instead of "const double%26amp;", because double is small enough, that it doesn't make sense to pass by reference.
Reply:i don't understand your code what u want to do please write it properly.
Reply:The only function you have that takes at least 3 parameters is calcBonus(). And you are passing a const as the 3rd parameter but it wants a reference. If RATE was an ordinary double, this would work. However, a const is much like a hard-code number (0.1). And passing a reference without making it a const reference implies that the function has the ability to *change* that value. But you cannot change 0.1 to have a value of anything except 0.1. (Unless you are using an ancient version of Fortran!).





Easiest fix to this is to change the function declaration so that you just pass a double as the 3rd parameter and not a reference to a double.


Help with this C++ Program?

"Write a complete program based on the functions in question 5 and 6 above. Add another function called print_okay that tells the user that he or she will it to the next gas station. Convert the if structure to an if / else and include the call to the print_okay function in the else clause.








Okay.. what was in the questions above is:





void print_warning()


{


cout %26lt;%26lt; "WARNING: Calculations indicate that you will run\n";


cout %26lt;%26lt; "out of fuel before the next available gas station.\n";





And





int main()


{


float miles_remaining, fuel_remaining, mpg, fuel_miles;





cout %26lt;%26lt; "How many miles are you from the next gas station? ";


cin %26gt;%26gt; miles_remaining;


cout %26lt;%26lt; "How much fuel do you have left (in gallons) ? ";


cin %26gt;%26gt; fuel_remaining;


cout %26lt;%26lt; "What is your average miles to the gallon? ";


cin %26gt;%26gt; mpg;





fuel_miles = fuel_remaining * mpg;

Help with this C++ Program?
First of all--do your own homework, but you need a function like this:





void print_okay()


{


cout %26lt;%26lt; "Calculations indicate that you will make it to the next gas station" %26lt;%26lt; endl;


}








and wherever the if statement is in the main function, you need an else after it that calls print_okay();


Please help with C++ Array?

For some reason what ever value (1-12) I enter for the month I have a return of “Jan” It builds fine … with no errors…but my array subscripts are not matching





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using std::cout;


using std::cin;


using std::endl;


using std::string;











int main()





{


int days[12] = {31, 28, 31, 30, 31, 30 , 31, 31 , 30, 31, 30, 31};


string month [12]= {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


string searchForMonth = "";





cout %26lt;%26lt; "Enter Month ID: ";


getline(cin, searchForMonth);





while (searchForMonth != "12")


{


int y = 0; //keeps track of array subscripts


while (y %26lt; 12 %26amp;%26amp; month[y] %26lt; searchForMonth)


y = y + 1;





if (y %26lt;= 12)





cout %26lt;%26lt; "Month: " %26lt;%26lt; month[y] %26lt;%26lt; endl;


cout %26lt;%26lt; "Enter Month ID: ";


getline (cin, searchForMonth);





}











return 0;


} //end of main function

Please help with C++ Array?
The reason you're getting "Jan" all the time is due to the second while loop condition. The string month[0] ("Jan") will always be greater than searchForMonth (assuming you're entering a number for searchForMonth).





So the second loop condition will always be false, and y will stay at 0.
Reply:I see a couple of problems.





string searchForMonth = "";





cout %26lt;%26lt; "Enter Month ID: ";


They are entering a STRING HERE


getline(cin, searchForMonth);





I understand "12" but why not use a compare method?


Its a string, not the ascii value of 12.


what happens if they enter a -1??


I think this is your reason right here.





while (searchForMonth != "12")


{


int y = 0; //keeps track of array subscripts








while (y %26lt; 12 %26amp;%26amp; month[y] %26lt; searchForMonth)


y = y + 1;





The IF below is not part of WHile


if (y %26lt;= 12)


cout %26lt;%26lt; "Month: " %26lt;%26lt; month[y] %26lt;%26lt; endl;





The statement below are not part of above IF


cout %26lt;%26lt; "Enter Month ID: ";


getline (cin, searchForMonth);





}//beginning while ends





I didnt get a chance to run it, so I just did this by sight
Reply:the man above me took the words right out of my mouth !
Reply:It could be these lines:





if (y %26lt;= 12)





cout %26lt;%26lt; "Month: " %26lt;%26lt; month[y] %26lt;%26lt; endl;





In your condition, you are accepting 12 as a valid value. So what is happening is you are getting





cout %26lt;%26lt; "Month: " %26lt;%26lt; month[12] %26lt;%26lt; endl; That's an overflow problem because the array subscript should only be between 0 and 11.





***********


You could try this in your loop:





int monthSearch;





cin%26gt;%26gt;monthSearch;





int index=monthSearch-1;


cout%26lt;%26lt;month[index] %26lt;%26lt; " " %26lt;%26lt; days[index]%26lt;%26lt;endl;





output of 3 entered into program:





Mar 31


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++

floral design

C++ Calander Program .......I'm sooooo close, I need your help.?

January starts in the right location but Feb, Mar, Apr, and every other month starts in the same spot as January, I'm sooo close please help me fix this last problem......





CODE





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;


using namespace std;





//function prototypes





int First_Day_Of_Month(int y, int m);


int Number_Days_Of_Month(int y, int m);


bool IsLeapYear(int y);


void Print_Version();


void Print_Head(int y);


void Print_Month(int y, int m);


void Print_Month_Head(int m);





void main ()


{


int year;


Print_Version();


cin%26gt;%26gt; year;


Print_Head(year);





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


{


Print_Month(year, i);


}


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


}





//Some Functions





void Print_Version()


{


cout%26lt;%26lt;"Enter any Year After 1753 to output a very pretty calendar for that year!\n";


}


void Print_Head(int y)


{


cout%26lt;%26lt;"\n\n"%26lt;%26lt;setw(21)%26lt;%26lt;y%26lt;%26lt;endl;


}


void Print_Month(int year, int month)


{


int firstday, number_days;





Print_Month_Head(month);


firstday = First_Day_Of_Month(year,month);


number_days = Number_Days_Of_Month(year,month);


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





for(int k=0; k%26lt;firstday; k++)


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


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


{


cout%26lt;%26lt;setw(5)%26lt;%26lt;i;


if((i + firstday)%7 == 0)


{


cout %26lt;%26lt; endl;


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


}


}


}


bool IsLeapYear(int year)


{


if(year%400 == 0)


{


return 1;


}


else if (year%4 == 0 %26amp;%26amp; year%100 != 0)


{


return 1;


}


else


return 0;


}


int First_Day_Of_Month(int year, int month)


{


int firstday;





for(month = 1; month%26lt;13; month++)


{


if(month%26lt;3)


{


month=month + 12;


year=year-1;


}


firstday = (1 + (2 * month) + ((6 * (month + 1)) / 10) + year + (year / 4) -


(year / 100) + (year / 400) + 1) % 7;





}


return firstday;


}


int Number_Days_Of_Month(int year, int month)


{


int Leapyear;


Leapyear = IsLeapYear(year);


if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)


{


return 31;


}


else if (month == 4 || month == 6 || month == 9 || month == 11)


{


return 30;


}


else if (Leapyear == 1)


{


return 29;


}


else


{


return 28;


}


}


void Print_Month_Head(int month)


{


if(month==1)


{


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


cout%26lt;%26lt;"\n January\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==2)


{


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


cout%26lt;%26lt;"\n February\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==3)


{


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


cout%26lt;%26lt;"\n March\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==4)


{


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


cout%26lt;%26lt;"\n April\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==5)


{


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


cout%26lt;%26lt;"\n May\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==6)


{


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


cout%26lt;%26lt;"\n June\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==7)


{


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


cout%26lt;%26lt;"\n July\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==8)


{


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


cout%26lt;%26lt;"\n August\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==9)


{


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


cout%26lt;%26lt;"\n September\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==10)


{


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


cout%26lt;%26lt;"\n October\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else if(month==11)


{


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


cout%26lt;%26lt;"\n November\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


else


{


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


cout%26lt;%26lt;"\n December\n\n Sun Mon Tue Wed Thu Fri Sat\n";


}


}








My output wont paste right here but you can see the problem, there is 5 days in the first week of every month....AAAARRRRGGGGHHHH!!!!!


/*Output





Enter any Year After 1753 to output a very pretty calendar for that year!


2008








2008


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


January





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30 31





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


February





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29





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


March





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30 31





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


April





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30





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


May





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30 31





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


June





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30





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


July





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30 31





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


August





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30 31





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


September





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30





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


October





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30 31





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


November





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30





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


December





Sun Mon Tue Wed Thu Fri Sat


1 2 3 4 5


6 7 8 9 10 11 12


13 14 15 16 17 18 19


20 21 22 23 24 25 26


27 28 29 30 31








Goodbye!


Press any key to continue


*/

C++ Calander Program .......I'm sooooo close, I need your help.?
i suspect the firstdayofmonth() function. it is not clear what it does and it seems to return the same value for each month.


here's the way i would approach it.








int firstdayofyear(int year)


{ do whatever to figure out the first weekday of the year}





int firstdayofmonth(int month, year)


{int prevmonth = 1, firstday = firstdayofyear(year);


while (prevmonth %26lt; month)


do


{


firstday += numberofdaysofmonth(month, year);


prevmonth++


}


firstday = firstday mod 7;


return firstday}





this separates the year calculations from the month calculations.


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.


What am i doing wrong here? c++ ( im getting errors)?

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





char moviename[50], adult[50], child[50];


int Six,Three,Total,AdultSales,ChildSales,Gr...





AdultSales = adult*6;


ChildSales = child*3;


GrossSales = AdultSales + ChildSales;








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





cout %26lt;%26lt; "Enter the movie's Name: ";


cin.get(moviename,50);


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


cout %26lt;%26lt; "Enter the number of adult tickets sold: ";


cin %26gt;%26gt; adult;


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


cout %26lt;%26lt; "Enter the number of child tickets sold: ";


cin %26gt;%26gt; child;


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











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


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


cout %26lt;%26lt; "INCOME STATEMENT" %26lt;%26lt; endl;


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





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


cout %26lt;%26lt; "Movie Name: "%26lt;%26lt;moviename%26lt;%26lt; endl;


cout %26lt;%26lt; "Adult Tickets Sold: "%26lt;%26lt;adult %26lt;%26lt; endl;


cout %26lt;%26lt; "Child Tickets Sold: "%26lt;%26lt;child%26lt;%26lt; endl;


cout %26lt;%26lt; "Gross Box Office Profits: " %26lt;%26lt; GrossSales %26lt;%26lt;endl;


cout %26lt;%26lt; "Net Box Office Profit: " %26lt;%26lt; endl;


cout %26lt;%26lt; "Amount Paid To Distributers" %26lt;%26lt; endl;


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

What am i doing wrong here? c++ ( im getting errors)?
instead of


char moviename[50], adult[50], child[50];


do


char moviename[50];


int adult[50], child[50];
Reply:I dunno, looks okay at first glance, but seeing the error messages would be very helpful.
Reply:What's the first error
Reply:At first glance it looks ok, make sure there is a ';' at the end of your int line. If I knew the error I may be able to narrow it down a little more for you.
Reply:At a glance...





You declare two arrays of characters:


char ... adult[50], child[50];





When you use the variable without the brace [] qualifier, you're actually using it as a pointer to the first member of the array.





So looking at your code, I see the following problems:





1. Calculation of variables AdultSales, ChildSales is performing pointer calculations instead of calculations using integer values.





2. You treat moviename as a string value on your cin statement (which is correct), but you don't do the same thing for adult and child. If you want adult and child to be strings, you need to enter them as strings and convert them to numeric equivalents. If you don't, you're just doing calculations on each characters ASCII code.





3. AdultSales, and ChildSales calculations are performed before you have values for adult and child sales. Remember that the equals (=) symbol is a one time assignment statement.





For example, the code:


x = 1;


y = x;


x = 2;


cout %26lt;%26lt; "The value of x: " %26lt;%26lt; x %26lt;%26lt; endl;


cout %26lt;%26lt; "The value of y: " %26lt;%26lt; y %26lt;%26lt; endl;





will have the following output:


The value of x: 2


The value of y: 1





You want to call your calculations after you have values for the variables used in them.





Hope that helps!


Integers and C+?

I need to loop a cin until the use inputs no number. what does the if statement have to be to do this? i tried if input==NULL but with integers, NULL = 0. i don't want to have that because 0 is such a common number. is this possible?





thus, i've written:





bool check;


int input;





while(check)


{


cin %26gt;%26gt; input;


if(input==????)


check=false


else


list.insertNode(input);


}

Integers and C+?
Hi :)





Strings have nothing to do with your question, ignore that previous answer.





I would suggest making your sentinel the number "-1".





You are working with a loop to insert numbers into a list, right?





Here's my suggestion. You don't need to use a boolean value to control the loop, though you can if you want. Instead, you could just simply test the number with a conditional statement (like


!=). Conditional statements return boolean variables anyways - For example:





int input;





cin %26gt;%26gt; input; // priming read





while (input != -1)


{


list.insertNode(input)


cin%26gt;%26gt; input; // internal read


} // end while





The first cin reads an integer in, and then decides what to do with it. The second one does the same for the rest of the cases.





Hope that helps :)





Rob
Reply:did you try...





IF(!input)
Reply:What kind of user input are you getting? C string or C++ string? If you're using a C string you can use the isdigit property and cycle through each character until finding a digit -- http://www.cppreference.com/stdstring/is...





Or if you don't want to use the properties you can just check each individual char and check if it's 0-9. Just do a For loop inside a For loop with a switch statement inside.

chelsea flower show

Help with C++! i don't what this error means and neither how to fix it! help!!!!!!!!!?

Error1error C2679: binary '%26gt;%26gt;' : no operator found which takes a right-hand operand of type 'std::basic_istream%26lt;_Elem,_Traits%26gt;' (or there is no acceptable conversion)


THIS IS MY CODE:


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;iomanip%26gt;





using namespace std;





int main()


{


//declare variables


string name = "";





//get a name from user


cout %26lt;%26lt; "Enter a 5 charater name: " %26lt;%26lt; endl;


cin %26gt;%26gt; getline(cin, name);





//determines if the name is 5 characters


while (name.length() != 5)


{


cout %26lt;%26lt; "You five character name is: ";


getline(cin, name);


}//endwhile





return 0;


} //end of main function

Help with C++! i don't what this error means and neither how to fix it! help!!!!!!!!!?
It must be cin.getline(); not cin %26gt;%26gt; getline();
Reply:Yes, the person before me is correct:





http://www.cplusplus.com/reference/iostr...





use cin.getline(arg1, arg2). See the referenced link above.


Integers and C+?

I need to loop a cin until the use inputs no number. what does the if statement have to be to do this? i tried if input==NULL but with integers, NULL = 0. i don't want to have that because 0 is such a common number. is this possible?





thus, i've written:





bool check;


int input;





while(check)


{


cin %26gt;%26gt; input;


if(input==????)


check=false


else


list.insertNode(input);


}

Integers and C+?
Hi :)





Strings have nothing to do with your question, ignore that previous answer.





I would suggest making your sentinel the number "-1".





You are working with a loop to insert numbers into a list, right?





Here's my suggestion. You don't need to use a boolean value to control the loop, though you can if you want. Instead, you could just simply test the number with a conditional statement (like


!=). Conditional statements return boolean variables anyways - For example:





int input;





cin %26gt;%26gt; input; // priming read





while (input != -1)


{


list.insertNode(input)


cin%26gt;%26gt; input; // internal read


} // end while





The first cin reads an integer in, and then decides what to do with it. The second one does the same for the rest of the cases.





Hope that helps :)





Rob
Reply:did you try...





IF(!input)
Reply:What kind of user input are you getting? C string or C++ string? If you're using a C string you can use the isdigit property and cycle through each character until finding a digit -- http://www.cppreference.com/stdstring/is...





Or if you don't want to use the properties you can just check each individual char and check if it's 0-9. Just do a For loop inside a For loop with a switch statement inside.


Help with C++! i don't what this error means and neither how to fix it! help!!!!!!!!!?

Error1error C2679: binary '%26gt;%26gt;' : no operator found which takes a right-hand operand of type 'std::basic_istream%26lt;_Elem,_Traits%26gt;' (or there is no acceptable conversion)


THIS IS MY CODE:


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;iomanip%26gt;





using namespace std;





int main()


{


//declare variables


string name = "";





//get a name from user


cout %26lt;%26lt; "Enter a 5 charater name: " %26lt;%26lt; endl;


cin %26gt;%26gt; getline(cin, name);





//determines if the name is 5 characters


while (name.length() != 5)


{


cout %26lt;%26lt; "You five character name is: ";


getline(cin, name);


}//endwhile





return 0;


} //end of main function

Help with C++! i don't what this error means and neither how to fix it! help!!!!!!!!!?
It must be cin.getline(); not cin %26gt;%26gt; getline();
Reply:Yes, the person before me is correct:





http://www.cplusplus.com/reference/iostr...





use cin.getline(arg1, arg2). See the referenced link above.


Help on c++?

I wrote a program that compute %26amp; print the Area of triangle :


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


main( )


{


const 1/2;


int b,h;


cout%26lt;%26lt;"enter b,h"%26lt;%26lt;endl;


cin%26gt;%26gt;b;


cin%26gt;%26gt;h;


cout%26lt;%26lt;"Area of Triangle="%26lt;%26lt;1/2*b*h;


}





please can any one tell me what's wrong with it .

Help on c++?
1) Remove const 1/2


2) Write b*h*1/2 instead of 1/2*b*h while printing





Your program will run











The MAIN REASON your program isn't giving right answer is you are printing 1/2*b*h. As the compiler reads from left to right and as the priority of '/' and '*' is equal, so it is taking this expression as 1/(2*b*h).





As you haven't mentioned any data type for the answer, compiler is treating it as an integer output. As 2*b*h becomes a large value, 1/(2*b*h) becomes zero (0). So your output is 0.
Reply:First remove const 1/2


It doesnt make sense





Now... since u are using 1/2.. it is a floating point value.


So just add this statement:





float area = 0.5 * b * h;


cout %26lt;%26lt; "Area of Triangle = " %26lt;%26lt; area;





Thats it ;)
Reply:It will give you error at


const 1/2


Sicne C++ does not allow "/" operator in the declaration of Const. If at all you are interested in so, try to use


() in the const declaration.


But I dont see any other error apart from this in the above code.

apple

Can someone please help me with C++?

i am not getting the average on this program why? my output is 0. what do i have wrong? this is my code:


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::fixed;


using std::setprecision;








int main()


{


//declare variables


int section = 1;


int grades = 0;


double totalGrades = 0.0;


double average = 0.0;





while (section %26lt; 3)


{


cout %26lt;%26lt; "Grades for Section " %26lt;%26lt; section %26lt;%26lt; ": " ;


cin %26gt;%26gt; grades;





while (grades %26gt; 0)


{


average = totalGrades / section;





cout %26lt;%26lt; "Next grade for Section " %26lt;%26lt; section %26lt;%26lt; ": " ;


cin %26gt;%26gt; grades;


} //end while





cout %26lt;%26lt; endl %26lt;%26lt; "Section " %26lt;%26lt; section %26lt;%26lt; " Average: " %26lt;%26lt; totalGrades %26lt;%26lt; endl %26lt;%26lt; endl;





section += 1;





average = 0.0;


} //end while


cout %26lt;%26lt; "End of the program" %26lt;%26lt; endl;


} //end of main function

Can someone please help me with C++?
Totalgrades is never being set, but you are setting average by the line:


"average = totalGrades / section;".


so:


average = 0 / section


Therefore average will always be 0.


Programming Question (C++)?

So im in a intro to programming class. I wrote a program and it runs, but not the way i want.


My code is:





#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;


double name, adult, child;





cout %26lt;%26lt; "Enter the movie's Name: ";


cin %26gt;%26gt; name;


cout %26lt;%26lt; "Enter the number of adult tickets sold: " %26lt;%26lt; endl;


cin %26gt;%26gt; adult;


cout %26lt;%26lt; "Enter the number of child tickets sold: " %26lt;%26lt; endl;


cin %26gt;%26gt; child;

















system("PAUSE");


return EXIT_SUCCESS;








I can type in the title of a movie. But then I cant plug in the numbers for adults and kids. also how can i get then to come up seprately. so...


Name of movie? (ENTER NAME) , click and then it goes to


Number of Adults attending (ENTER AMOUNT) click and then it goes


Number of kids attending (ENTER AMOUNT) CLICK then done

Programming Question (C++)?
use char name[];


double adult,child;


it will work
Reply:You should make the variable 'name' a string type. Double is an integer type.
Reply:replace the line which declares the variables....





instead of "double name, adult, child;"





use this...


...................





string name;


double adult, child;





...................


since it's c++, use string class...


later you will learn more about this and how to handle strings...
Reply:name variable should be char name[MAX_MOVIE_LENGTH];


or add MFC support to your project and use String name;


Shortening this C++ program?

#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


#include %26lt;ctime%26gt;


using namespace std;


using std::srand;





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


{


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





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


ta = 1000;


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


n = 10;


while (n %26gt; 0)


{


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


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


cin %26gt;%26gt; wa;





while (wa %26gt; ta)


{


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


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


cin %26gt;%26gt; wa;


}





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


{


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


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


cin %26gt;%26gt; wa;


}

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





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


{


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


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


cin %26gt;%26gt;wa;


}





And then combine your other conditions:





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


{


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


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


cin %26gt;%26gt; ga;


}