how to convert this code into C program #include using namespace std; float tota
ID: 3604493 • Letter: H
Question
how to convert this code into C program
#include using namespace std;
float total(float,float,float);
#include <iostream>
using namespace std;
float total(float,float,float);
int units;
int main()
{
int ch,c0ch1;//c0ch1 is the cases integer variable,ch is the choice for selecting session
float enrollmentfee,studentservicesfee,stickerfee, idCardfee,parkingfee,totalfee;
char choice// it is for selecting yes or no i.e. y or n;
cout << "Hello world!" << endl;
cout << "enter units ";
cin>>units;
cout<< "Is this Fall[0], Winter[1], Spring[2] or Summer[3] session ";
cin>>ch;
switch(ch)
{
case 0://for Fall
cout<<"Are you a state resident[0] or not[1]: ";
cin>>c0ch1;
studentservicesfee=19;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1){
enrollmentfee=335;
}
cout<<"Want a parking decal? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
parkingfee=85;
}
else if(choice=='n' || choice=='N'){
parkingfee=0;
}
cout<<"Want an AS sticker? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N'){
stickerfee=0;
studentservicesfee+=stickerfee;
}
cout<<" Want an ID card? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N'){
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
cout<<"For Fall semester, your total fees are : "<<totalfee;
break;
case 1:// for winter
cout<<"Are you a state resident[0] or not[1]: ";
cin>>c0ch1;
studentservicesfee=16;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1){
enrollmentfee=335;
}
cout<<"Want a parking decal? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
parkingfee=45;
}
else if(choice=='n' || choice=='N'){
parkingfee=0;
}
cout<<"Want an AS sticker? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N'){
stickerfee=0;
studentservicesfee+=stickerfee;
}
cout<<" Want an ID card? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N'){
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
cout<<"For Fall semester, your total fees are : "<<totalfee;
break;
case 2:// for spring
cout<<"Are you a state resident[0] or not[1]: ";
cin>>c0ch1;
studentservicesfee=19;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1){
enrollmentfee=335;
}
cout<<"Want a parking decal? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
parkingfee=85;
}
else if(choice=='n' || choice=='N'){
parkingfee=0;
}
cout<<"Want an AS sticker? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N'){
stickerfee=0;
studentservicesfee+=stickerfee;
}
cout<<" Want an ID card? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N'){
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
cout<<"For Fall semester, your total fees are : "<<totalfee;
break;
case 3:// for summer
cout<<"Are you a state resident[0] or not[1]: ";
cin>>c0ch1;
studentservicesfee=16;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1){
enrollmentfee=335;
}
cout<<"Want a parking decal? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
parkingfee=45;
}
else if(choice=='n' || choice=='N'){
parkingfee=0;
}
cout<<"Want an AS sticker? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N'){
stickerfee=0;
studentservicesfee+=stickerfee;
}
cout<<" Want an ID card? [y/n]: ";
cin>>choice;
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N'){
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
cout<<"For Fall semester, your total fees are : "<<totalfee;
break;
default:cout<<"please enter correct option ";
}
return 0;
}
float total(float enroll,float park,float service)
{
enroll=enroll*units;
cout<<enroll<<" "<<park<<" "<<service<<" ";
return (enroll+park+service);
}
int units; int main() { int ch,c0ch1;//c0ch1 is the cases integer variable,ch is the choice for selecting session float enrollmentfee,studentservicesfee,stickerfee, idCardfee,parkingfee,totalfee; char choice// it is for selecting yes or no i.e. y or n; cout << "Hello world!" << endl; cout << "enter units "; cin>>units; cout<< "Is this Fall[0], Winter[1], Spring[2] or Summer[3] session "; cin>>ch; switch(ch) { case 0://for Fall cout<<"Are you a state resident[0] or not[1]: "; cin>>c0ch1; studentservicesfee=19; if(c0ch1==0) { enrollmentfee=46; } else if(c0ch1==1){ enrollmentfee=335; } cout<<"Want a parking decal? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { parkingfee=85; } else if(choice=='n' || choice=='N'){ parkingfee=0; } cout<<"Want an AS sticker? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { stickerfee=19.5; studentservicesfee+=stickerfee; } else if(choice=='n' || choice=='N'){ stickerfee=0; studentservicesfee+=stickerfee; } cout<<" Want an ID card? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { idCardfee=13; studentservicesfee+=idCardfee; } else if(choice=='n' || choice=='N'){ idCardfee=0; studentservicesfee+=idCardfee; } totalfee=total(enrollmentfee,parkingfee,studentservicesfee); cout<<"For Fall semester, your total fees are : "<>c0ch1; studentservicesfee=16; if(c0ch1==0) { enrollmentfee=46; } else if(c0ch1==1){ enrollmentfee=335; } cout<<"Want a parking decal? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { parkingfee=45; } else if(choice=='n' || choice=='N'){ parkingfee=0; } cout<<"Want an AS sticker? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { stickerfee=19.5; studentservicesfee+=stickerfee; } else if(choice=='n' || choice=='N'){ stickerfee=0; studentservicesfee+=stickerfee; } cout<<" Want an ID card? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { idCardfee=13; studentservicesfee+=idCardfee; } else if(choice=='n' || choice=='N'){ idCardfee=0; studentservicesfee+=idCardfee; } totalfee=total(enrollmentfee,parkingfee,studentservicesfee); cout<<"For Fall semester, your total fees are : "<>c0ch1; studentservicesfee=19; if(c0ch1==0) { enrollmentfee=46; } else if(c0ch1==1){ enrollmentfee=335; } cout<<"Want a parking decal? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { parkingfee=85; } else if(choice=='n' || choice=='N'){ parkingfee=0; } cout<<"Want an AS sticker? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { stickerfee=19.5; studentservicesfee+=stickerfee; } else if(choice=='n' || choice=='N'){ stickerfee=0; studentservicesfee+=stickerfee; } cout<<" Want an ID card? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { idCardfee=13; studentservicesfee+=idCardfee; } else if(choice=='n' || choice=='N'){ idCardfee=0; studentservicesfee+=idCardfee; } totalfee=total(enrollmentfee,parkingfee,studentservicesfee); cout<<"For Fall semester, your total fees are : "<>c0ch1; studentservicesfee=16; if(c0ch1==0) { enrollmentfee=46; } else if(c0ch1==1){ enrollmentfee=335; } cout<<"Want a parking decal? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { parkingfee=45; } else if(choice=='n' || choice=='N'){ parkingfee=0; } cout<<"Want an AS sticker? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { stickerfee=19.5; studentservicesfee+=stickerfee; } else if(choice=='n' || choice=='N'){ stickerfee=0; studentservicesfee+=stickerfee; } cout<<" Want an ID card? [y/n]: "; cin>>choice; if(choice=='y' || choice=='Y') { idCardfee=13; studentservicesfee+=idCardfee; } else if(choice=='n' || choice=='N'){ idCardfee=0; studentservicesfee+=idCardfee; } totalfee=total(enrollmentfee,parkingfee,studentservicesfee); cout<<"For Fall semester, your total fees are : "<
Explanation / Answer
Here is the C version for you:
#include <stdio.h>
float total(float,float,float);
int units;
int main()
{
int ch,c0ch1;//c0ch1 is the cases integer variable,ch is the choice for selecting session
float enrollmentfee,studentservicesfee,stickerfee, idCardfee,parkingfee,totalfee;
char choice; // it is for selecting yes or no i.e. y or n;
printf("Hello world! ");
printf("enter units ");
scanf("%i", &units);
printf("Is this Fall[0], Winter[1], Spring[2] or Summer[3] session ");
scanf("%i", &ch);
switch(ch)
{
case 0://for Fall
printf("Are you a state resident[0] or not[1]: ");
scanf("%i", &c0ch1);
studentservicesfee=19;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1)
{
enrollmentfee=335;
}
printf("Want a parking decal? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
parkingfee=85;
}
else if(choice=='n' || choice=='N')
{
parkingfee=0;
}
printf("Want an AS sticker? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N')
{
stickerfee=0;
studentservicesfee+=stickerfee;
}
printf(" Want an ID card? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N')
{
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
printf("For Fall semester, your total fees are : %.2f ", totalfee);
break;
case 1:// for winter
printf("Are you a state resident[0] or not[1]: ");
scanf("%i", &c0ch1);
studentservicesfee=16;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1)
{
enrollmentfee=335;
}
printf("Want a parking decal? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
parkingfee=45;
}
else if(choice=='n' || choice=='N')
{
parkingfee=0;
}
printf("Want an AS sticker? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N')
{
stickerfee=0;
studentservicesfee+=stickerfee;
}
printf(" Want an ID card? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N')
{
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
printf("For Fall semester, your total fees are : %.2f ", totalfee);
break;
case 2:// for spring
printf("Are you a state resident[0] or not[1]: ");
scanf("%i", &c0ch1);
studentservicesfee=19;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1)
{
enrollmentfee=335;
}
printf("Want a parking decal? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
parkingfee=85;
}
else if(choice=='n' || choice=='N')
{
parkingfee=0;
}
printf("Want an AS sticker? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N')
{
stickerfee=0;
studentservicesfee+=stickerfee;
}
printf(" Want an ID card? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N')
{
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
printf("For Fall semester, your total fees are : %.2f ", totalfee);
break;
case 3:// for summer
printf("Are you a state resident[0] or not[1]: ");
scanf("%i", &c0ch1);
studentservicesfee=16;
if(c0ch1==0)
{
enrollmentfee=46;
}
else if(c0ch1==1)
{
enrollmentfee=335;
}
printf("Want a parking decal? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
parkingfee=45;
}
else if(choice=='n' || choice=='N')
{
parkingfee=0;
}
printf("Want an AS sticker? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
stickerfee=19.5;
studentservicesfee+=stickerfee;
}
else if(choice=='n' || choice=='N')
{
stickerfee=0;
studentservicesfee+=stickerfee;
}
printf(" Want an ID card? [y/n]: ");
scanf(" %c", &choice);
if(choice=='y' || choice=='Y')
{
idCardfee=13;
studentservicesfee+=idCardfee;
}
else if(choice=='n' || choice=='N')
{
idCardfee=0;
studentservicesfee+=idCardfee;
}
totalfee=total(enrollmentfee,parkingfee,studentservicesfee);
printf("For Fall semester, your total fees are : %.2f ", totalfee);
break;
default: printf("please enter correct option ");
}
return 0;
}
float total(float enroll,float park,float service)
{
enroll=enroll*units;
printf("%f %f %f ", enroll, park, service);
return (enroll+park+service);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.