Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m using C++ in VS and I\'m trying to run the following program. As soon as I

ID: 3550871 • Letter: I

Question

I'm using C++ in VS and I'm trying to run the following program. As soon as I put in my name after the 2nd cout statement, the program ends. What do I need to add to the program in order for it to execute the next line which is "Enter your last name"?


#include <iostream>

#include <string>

#include <iomanip>


using namespace std;

int main()

{

string raptor_prompt_variable_zzyz;

float StreetName;

int ZipCode;

float City;

float StreetType;

float LastName;


float State;

float Total;

float PurchaseAmount;

float FirstName;

int Address;


float Shipping = 1.99;


cout << "Bayou Online Retail" << endl;

cout << "Enter Your First Name ";

cin >> FirstName;

cout<< "Enter Your Last Name";

cin >> LastName;

raptor_prompt_variable_zzyz = "Enter Street Address (Number Portion Only)";

cout << raptor_prompt_variable_zzyz << endl;

cin >> Address;

raptor_prompt_variable_zzyz = "Enter Street Name";

cout << raptor_prompt_variable_zzyz << endl;

cin >> StreetName;

raptor_prompt_variable_zzyz = "Enter Street Type (Ave, St, Rd, or Ln)";

cout << raptor_prompt_variable_zzyz << endl;

cin >> StreetType;

raptor_prompt_variable_zzyz = "Enter City";

cout << raptor_prompt_variable_zzyz << endl;

cin >> City;

raptor_prompt_variable_zzyz = "Enter State";

cout << raptor_prompt_variable_zzyz << endl;

cin >> State;

raptor_prompt_variable_zzyz = "Enter Zip Code";

cout << raptor_prompt_variable_zzyz << endl;

cin >> ZipCode;

raptor_prompt_variable_zzyz = "Enter Purchase Amount";

cout << raptor_prompt_variable_zzyz << endl;

cin >> PurchaseAmount;

Total = PurchaseAmount + Shipping;

cout << "*Bayou Online Retail Receipt*" << endl;

cout << "Customer Name: " <<FirstName<< LastName << endl;

cout << "Address: " << Address << StreetName << StreetType << endl;

cout << "" << City << State << ZipCode << endl;

cout << "The amount purchased is $" << PurchaseAmount << endl;

cout << "The Shipping Amount is $" << Shipping << endl;

cout << "The Total amount is $" << Total << endl;

return 0;

}



Explanation / Answer

The problem with your code is that you have declared string variables such as LastName, FirstName, etc as float variables, which is wrong because the float variable stores decimal values and not strings.



That is why as soon as you are providing a string variable like "John" as your FirstName, the program is exiting. Change the declaration to string types ffor those variables whose values will be provided as string.



The corrected working program is this:


#include <iostream>


#include <string>


#include <iomanip>



using namespace std;


int main()


{


string raptor_prompt_variable_zzyz;


string StreetName, City, StreetType, LastName, State, FirstName, Address;


int ZipCode;


float Total;


float PurchaseAmount;


float Shipping = 1.99;



cout << "Bayou Online Retail" << endl;


cout << "Enter Your First Name ";


cin >> FirstName;


cout<< "Enter Your Last Name ";


cin >> LastName;


raptor_prompt_variable_zzyz = "Enter Street Address (Number Portion Only)";


cout << raptor_prompt_variable_zzyz << endl;


cin >> Address;


raptor_prompt_variable_zzyz = "Enter Street Name ";


cout << raptor_prompt_variable_zzyz << endl;


cin >> StreetName;


raptor_prompt_variable_zzyz = "Enter Street Type (Ave, St, Rd, or Ln)";


cout << raptor_prompt_variable_zzyz << endl;


cin >> StreetType;


raptor_prompt_variable_zzyz = "Enter City ";


cout << raptor_prompt_variable_zzyz << endl;


cin >> City;


raptor_prompt_variable_zzyz = "Enter State ";


cout << raptor_prompt_variable_zzyz << endl;


cin >> State;


raptor_prompt_variable_zzyz = "Enter Zip Code ";


cout << raptor_prompt_variable_zzyz << endl;


cin >> ZipCode;


raptor_prompt_variable_zzyz = "Enter Purchase Amount ";


cout << raptor_prompt_variable_zzyz << endl;


cin >> PurchaseAmount;


Total = PurchaseAmount + Shipping;


cout << "*Bayou Online Retail Receipt* " << endl;


cout << "Customer Name: " <<FirstName<< LastName << endl;


cout << "Address: " << Address << StreetName << StreetType << endl;


cout << "" << City << State << ZipCode << endl;


cout << "The amount purchased is $" << PurchaseAmount << endl;


cout << "The Shipping Amount is $" << Shipping << endl;


cout << "The Total amount is $" << Total << endl;


return 0;


}


Tell me if you have any more doubts in this. ............


PLEASE RATE THE ANSWER..........