i got these 2 programs, i wrote them but i get an error in the last 3 lines in t
ID: 3629119 • Letter: I
Question
i got these 2 programs, i wrote them but i get an error in the last 3 lines in the c++ program and in the last line in the c program, can any programmer help me#include<iostream>
using namespace std;
int main()
{
const int QUARTER=25,DIME=10,NECKLE=5,PENNY=1;
int num_quarters,num_dimes,num_nickels,num_pennies,total_cents,remainder,again;
cout<<"This program will calculate the minimal number of coins needed ";
cout<<"in order to make change for a given amount of cents. ";
cout<<" ";
do
{
cout<<"Please enter an amount in cents: ";
cin>>total_cents;
if(total_cents<0)
{
cout<<"Cannot calculate negative change";
}
else
{
cout<<"The optimal change for 41 cent(s) is:";
num_quarters=total_cents/25;
remainder=total_cents%25;
num_dimes=remainder/10;
remainder=remainder%10;
num_nickels=remainder/5;
remainder=remainder%5;
num_pennies=remainder;
if(num_quarters>0)
{
cout<<num_quarters<<"quarter";
if(num_quarters>1)
{
cout<<"s";
}
}
if(num_dimes>0)
{
cout<<num_dimes<<"dime";
if(num_dimes>1)
{
cout<<"s";
}
}
if(num_nickels>0)
{
cout<<num_nickels<<"nickel";
if(num_nickels>1)
{
cout<<"s";
}
}
if(num_pennies>0)
{
cout<<num_pennies<<"penny";
if(num_pennies>1)
{
cout<<"s";
}
}
cout<<"Would you like to calculate change again (Y/N)? ";
cin>>again;
}while(again=='y'\again=='Y')
return 0;
}
#include<stdio.h>
int main()
{
double radius,area,surface_area,volume,circumference;
int option;
const double PI=3.1415926;
printf("Choose an option to calculate:");
printf(" (1) Circumference of a circle");
printf(" (2) Area of a circle");
printf(" (3) Surface area of a sphere");
printf(" (4) Volume of a sphere");
printf(" (5) Quit");
printf(" ");
do
{
printf("Enter option => ");
scanf("%i",&option);
switch(option)
{
case1:
printf("Enter the radius => ");
scanf("%lf",& radius);
circumference=(2*PI)*radius;
printf("The circumference is %4f"),circumference;
break;
pintf(" ");
case2:
printf("Enter the radius => ");
scanf("%lf",& radius);
area=PI*(radius*radius);
printf("The area is %4f"),area;
break;
pintf(" ");
case3:
printf("Enter the radius => ");
scanf("%lf",& radius);
surface_area=4*PI*(radius*radius);
printf("The surface_area is %4f"),surface_area;
break;
pintf(" ");
case4:
printf("Enter the radius => ");
scanf("%lf",& radius);
volume=(4.0/3)*PI*radius*radius*radius;
printf("The volume is %4f"),volume;
break;
} while (option!=5);
printf("Thanks for playing!");
return 0;
}
Explanation / Answer
please rate - thanks
or is || not \
plus fixed some other stuff
indent-makes life easier
#include<iostream>
using namespace std;
int main()
{
const int QUARTER=25,DIME=10,NECKLE=5,PENNY=1;
int num_quarters,num_dimes,num_nickels,num_pennies,total_cents,remainder;
char again;
cout<<"This program will calculate the minimal number of coins needed ";
cout<<"in order to make change for a given amount of cents. ";
cout<<" ";
do
{
cout<<"Please enter an amount in cents: ";
cin>>total_cents;
if(total_cents<0)
{
cout<<"Cannot calculate negative change";
}
else
{
cout<<"The optimal change for "<<total_cents<<" cent(s) is: ";
num_quarters=total_cents/25;
remainder=total_cents%25;
num_dimes=remainder/10;
remainder=remainder%10;
num_nickels=remainder/5;
remainder=remainder%5;
num_pennies=remainder;
}
if(num_quarters>0)
{
cout<<num_quarters<<" quarter";
if(num_quarters>1)
{
cout<<"s";
}
cout<<endl;
}
if(num_dimes>0)
{
cout<<num_dimes<<" dime";
if(num_dimes>1)
{
cout<<"s";
}
cout<<endl;
}
if(num_nickels>0)
{
cout<<num_nickels<<" nickel";
if(num_nickels>1)
{
cout<<"s";
}
cout<<endl;
}
if(num_pennies>0)
{
cout<<num_pennies<<" penny";
if(num_pennies>1)
{
cout<<"s";
}
cout<<endl;
}
cout<<"Would you like to calculate change again (Y/N)? ";
cin>>again;
}while(again=='y'||again=='Y');
system("pause");
return 0;
}
----------------------
you wanted not , bunch of other problems
#include<stdio.h>
int main()
{
double radius,area,surface_area,volume,circumference;
int option;
const double PI=3.1415926;
do
{printf("Choose an option to calculate:");
printf(" (1) Circumference of a circle");
printf(" (2) Area of a circle");
printf(" (3) Surface area of a sphere");
printf(" (4) Volume of a sphere");
printf(" (5) Quit");
printf(" ");
printf("Enter option => ");
scanf("%i",&option);
switch(option)
{
case 1:
printf("Enter the radius => ");
scanf("%lf",& radius);
circumference=(2*PI)*radius;
printf("The circumference is %4f",circumference);
printf(" ");
break;
case 2:
printf("Enter the radius => ");
scanf("%lf",& radius);
area=PI*(radius*radius);
printf("The area is %4f",area);
printf(" ");
break;
case 3:
printf("Enter the radius => ");
scanf("%lf",& radius);
surface_area=4*PI*(radius*radius);
printf("The surface_area is %4f",surface_area);
printf(" ");
break;
case 4:
printf("Enter the radius => ");
scanf("%lf",& radius);
volume=(4.0/3)*PI*radius*radius*radius;
printf("The volume is %4f",volume);
break;
}
printf(" ");
} while (option!=5);
printf("Thanks for playing!");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.