Sunday, August 2, 2009

Need help with C++. Program closing on a simplish program.?

Hey, I'm learning to prgram in C++ with the help of a book I bought. However, for some reason all the exercises in the book do not have cin.get() or system("PAUSE") and do not mention anything about using these to stop the program from closing (very frustrating!)





Here is my program that has been copied straight from the book and is closing after I enter a number. ( Or after I press enter after I have entered the number in the case that I have put a cin.get() in)





#include %26lt;iostream%26gt;


using namespace std;





int main( void )


{





int number;





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


cin%26gt;%26gt; number;


if (number %26gt;= 1 %26amp;%26amp; number %26lt;= 100 %26amp;%26amp; (number % 3 == 0))


{


number = number * 2;


}


else if (number %26gt;= 1 %26amp;%26amp; number %26lt;= 100


%26amp;%26amp; !(number % 3 == 0))


{


number = number * 3;


}


else if (!(number %26gt;= 1 %26amp;%26amp; number %26lt;= 100))


{


number = number * number % 3;


}





cin.get();


cin.get();


return 0;


}





Help would be great thanks.





Doug

Need help with C++. Program closing on a simplish program.?
IMO, the reason why the exercises don't have a system("pause") is because not all C++ editors/IDE need them. Dev C++ is the only IDE I know that closes after program execution.





In your program, I don't think that you need the cin.get(); lines, just 'system("pause")' before the 'return 0;'. You may also want to display your programs result, just add a 'cout %26lt;%26lt; number;'.
Reply:Hey thanks... the cout%26lt;%26lt;number was all I needed. I must have forgot that.





I'm using the beta version of Microsoft Visual Studio 2008. Report It



Write a C program to define a structure Student that would contain student name, Marks of 3 subjects?

Write a C program to define a structure Student that would contain student name, Marks of 3 subjects .The program must read 5 student record in an array of structure and display the details of a student who scored highest.(use pointer to structure)

Write a C program to define a structure Student that would contain student name, Marks of 3 subjects?
are you in ap college and is this question was given to you by sameer sir if yes then only i can help you he gave me that assignment two years back
Reply:i never got answers to such question and further more all such questions atleast mine get deleted so good luck in finding an answer to ur question even if u are just asking out of curiosity(not likely)(or because of lack of good teachers) its regarded as doing ur homework or uni assignment for you.
Reply:You are still trying to do this assignment?
Reply:For getting project assignment help there are better websites,e.g. http://getafreelnacer.com/


Write a C++ program to create functions that calculate the value of Xn.?

Write a program in 'c' language to merge the contents of two binary search trees into one. Also, calculate the time and space complexities of your program?

Write a C++ program to create functions that calculate the value of Xn.?
Try this:


http://www.rentacoder.com/RentACoder/def...





Good Luck


Write a C++ program to print a triangle composed of a symbol.?

Write a C++ program to print a triangle composed of a symbol. The number of lines and the symbol should be entered as input from the keyboard. For example, if the input values are * and 7, the output is as follows:








Do you wish to continue? (y = yes, n = no): y





Enter the symbol to be used to draw the triangle: *


How many lines do you want the triangle to be? 7





*


***


*****


*******


*********


***********


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





Thank you for using this program.











(The triangle really isnt a right triangle it should be a normal one but it doesnt show up right here.)

Write a C++ program to print a triangle composed of a symbol.?
Do you have a specific question or just wanting someone to do you homework?

umbrella plant

After a C++ program, is there any way to make it not say...?

After a C++ program, is there any way to make it not say press any key to continue...? I am using Dev-C++ 4.9.8.0.


HELP!!!!!!

After a C++ program, is there any way to make it not say...?
that is just the debugger running it. Run it normally through a normal DOS console or command prompt and you won't see it. Basically that is there to keep the window from closing without user interaction.


Problem on C program(strings)...please try to solve.?

write a C function void str_copy_drop(const char * string1, char * string2, char ch)


which copies the string string1 to string2 but with all occurrences of the character


passed as parameter ch omitted.








HERE IS WHAT I HAVE TRIED: its funny but can you check it and write me a correct program..





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


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


void str_copy_drop(const char *string1, char *string2, char ch);








void str_copy_drop(const char *string1, char *string2, char ch)


{


char *s1[20],*s2[20];








FILE *input;


input =fopen("string.txt","r");





fscanf(input,"%s",%26amp;s1);





s2= strcpy(s2,s1);


printf("\ncopied string is %s\n",s2);


}








above programs is wrong...i need solution for question described above..





Many thanks!!

Problem on C program(strings)...please try to solve.?
Use this function instead of yours. It would work fine.





void copy(char *s1,char *s2,char ch)


{


while(*s1!='\0')


{


if(*s1!=ch)


{


*s2=*s1;


s2++;


}


s1++;


}


*s2='\0';


}








U can ask more such..








OM NAMAH SHIVAY
Reply:/*


copy all characters from string1 into string2 except ch





method:


walks through each character in string1 using a pointer to


the characters, stopping at the C end-of-string char '\0', and


steps the pointer by the sizeof(char)





appends an end-of-string char to the output string2 after all valid characters have been copied.





NOTE BENE: output buffer (string2) must be sufficient to hold all characters of input buffer (string1). No checking is done to ensure this here.


*/


void str_copy_drop(const char *string1, char *string2, char ch) {





if (( 0 != string1 ) %26amp;%26amp; ( 0 != string2)) {


char* p1 = (char*)string1;


char* p2 = string2;





while ( (*p1) != '\0' ) {


if ( (*p1) != ch ) {


(*p2) = (*p1);


p2 += sizeof(char);


}


p1 += sizeof(char);


}


(*p2) = '\0';


}


}





You'll have to format the indentation yourself, as yA doesn't allow tabs.
Reply:you would have to go through the string, character by character and compare it with the parameter ch. if it matches then dont copy it to the new string. you need to know the length of the string so you know how many characters to compare.





pseudocode:


set 2 counters to 0


get length of string


loop "length of string" times


if string1[couter1] = !ch


copy string1[counter1] to string2[counter2]


increment counter2


loop until at end of string1





just a note (going by your function declaration), the file should be opened outside of the routine and read. then pass the pointer to the string. you dont need the "char s1, s2 pointers since you are passing the string pointers to the function (which you are not using by the way).


Question abot C program?

we write a program in a compilar %26amp; save it .c ,how does the compilar convert it in .exe file where r these exe files saved.





please provide me with complete detail im new to programing

Question abot C program?
The location of the exe depents of the compiler.


What compiler do you use?