为什么 while 循环体内的代码没有被执行

问题描述 投票:0回答:1

我无法运行 while 循环。

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string mystr1;
    string mystr2;

    cout << "Please provide your first and last name" << endl;

    getline (cin, mystr1);

    cout << endl;

    cout << "Please provide your shipping address"  << endl;

    getline (cin, mystr2);

    cout << endl;

    cout << "Hello " << mystr1 << " and welcome to Faulk Couture    
    Handbags Boutique" << endl; // prints Hello and welcome to Faulk 
    Couture Handbags Boutique

    cout << endl;

    cout << "We have a variety of specialty and fashionable handbags to      
    select from.  Please see below for the available products and their  
    descriptions." << endl;

    cout << endl;

    cout << "Product 1: Crosby Carryall in black priced at $395. This  
    sophisticated and spacious Crosby Carryall is a work-to-weekend favorite 
    and is finished with " << endl;
    cout << "bound leather edges, a detachable leather strap and petite 
    brass turnlocks securing its two zippered compartments."<< endl;

    cout << endl;

    cout << "Product 2: Prairie satchel with chain nude priced at $450. 
    Crafted in lightweight pebble leather with a bit of sheen, this 
    gracefully curved shape distills" <<endl;
    cout << "the satchel to its purest form. The simple design is finished  
    with a slender strap and an elegant chain detail that detaches for a 
    different look." << endl;

    cout << endl;

    cout << "Product 3: Faulk Swagger 20 brown priced at $325. This 
    Statement belting with double-turnlock hardware is one of our most 
    popular designs with a little bit of “swagger.” "<< endl;
    cout << "Named for a bold, brass-trimmed Bonnie Cashin design from 1967, 
    this very modern carryall in refined pebble leather comes finished with 
    a detachable strap for crossbody wear." << endl;

    cout << endl;

    cout << "Product 4: Zip top tote in brown priced at $285. This 
    sophisticated and light weight in signature canvas with hand-finished  
    leather trim, this aptly named tote is made for one-the-go ease." <<  
    endl;
    cout << "A modern, flared shape and oversized strap anchors add playful 
    proportions to its spacious, brightly lined design." << endl;

    cout << endl;

    cout << "Product 5: Wristlet 24 priced at $175. This striking, feminine 
    design in polished pebble leather has space enough for a tablet and an 
    elegant chain that converts it from wristlet to top handle." << endl;
    cout << "A dog-leash clip on the strap and an embossed hangtag charm 
    finish it with signature Faulk Couture Style." << endl;

    cout << endl;

    double cost, total, amount;
    int product;

    cout << "Please enter the product number for your bag choice" << endl;

    cin >> product;

    cout <<"The respective price for this bag is: " << endl;

    cin>>cost;

    cout<<"Please enter the quantity you would like to purchase for this 
    bag choice" << endl;

    cin>>amount;

    total = cost*amount;

    cout <<"Your total purchase price for " <<amount<< " qty of product 
    number " <<product<< " is " <<total<<"."<< endl;

    int choice=1;
    while (choice==1);
    {
        cout << "To purchase another bag, please enter 1 (anything else to 
        quit)" << endl;

        cin >> choice;

        cout << "Please enter the product number for your next bag choice" <<   
        endl;

        cin >> product;

        cout << "The respective price for this bag is: " << endl;

        cin >> cost;

        cout << "Please enter the quantity you would like to purchase for this 
        bag choice" << endl;

        cin >> amount;

        total = cost*amount;

        cout <<"Your total purchase price for " <<amount<< " qty of product 
        number " <<product<< " is " <<total<<"."<< endl;
    }
    
    cout << endl;
    return 0;
}
c++ while-loop
1个回答
4
投票

您用分号结束 while 循环,这就是它没有进入 while 循环的原因

这是没有分号的 while 循环

while (choice==1) {
    cout << "To purchase another bag, please enter 1 (anything else to 
    quit)" << endl;

    cin >> choice;

    cout << "Please enter the product number for your next bag choice" <<   
    endl;

    cin >> product;

    cout << "The respective price for this bag is: " << endl;

    cin >> cost;

    cout << "Please enter the quantity you would like to purchase for this 
bag choice" << endl;

    cin >> amount;

    total = cost*amount;

    cout <<"Your total purchase price for " <<amount<< " qty of product 
number " <<product<< " is " <<total<<"."<< endl;
}
© www.soinside.com 2019 - 2024. All rights reserved.