Tuesday, July 28, 2009

C++.... Help me fix this code, please?

//Program will find the product of a collection of integers from the user. Terminates when "0" is entered.





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


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


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


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





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


int main(void)


{


clrscr();


textcolor(RED+BLUE);


int i;


int product;


int num;


int bay;


int genki;


int genki2 = 1;





cprintf("Hello. This program will end when you type zero.\r\n");


clrscr();


cout%26lt;%26lt;"Please enter your first integer: ";


cin%26gt;%26gt;num;


clrscr();





if(num !=0)


{


cout%26lt;%26lt;"Please enter an integer: ";


cin%26gt;%26gt;i;


clrscr();


product=i*num;


}





if (product !=0)


{


cout%26lt;%26lt;"Your product is currently "%26lt;%26lt;product%26lt;%26lt;" \n\n";


getch();


clrscr();


}








if(i==0)


{


exit(1);


}





if(num==0)


{


exit(1);


}








do


{


cprintf("Please enter another integer: ");


cin%26gt;%26gt;bay;


clrscr();


bay=bay*product;

C++.... Help me fix this code, please?
You are making the code so complicated. Here is a solution





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





int main() {


int num = 1, product = 1;





printf("Enter an integer (0 to end): ");


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





while (num != 0) {


product *= num;


printf("The product so far is %d.\n\n", product);


printf("Enter an integer (0 to end): ");


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


}





return 0;


}
Reply:I am sorry.I dont understand a thing.
Reply:Put an else of if(num!=0) and exit, if you still need help you may contact a C expert at websites like http://askexpert.info/

hibiscus

No comments:

Post a Comment