Loops 编程理货系统C++;还显示结果的条形图 #include//include头文件 #包括 使用名称空间std; int main()//主体fcn { int-answer;//删除整数并初始化它们 int a=0; int b=0; int c=0; int i=0; int j=0; int k=0; while(answer!=0)//开始执行while循环条件,除非等于0 { 不能替换这部分代码: #include <iostream> //include header files #include <string> using namespace std; int main () //main body fcn { int answer;//delcaring integers and initializing them int a = 0; int b = 0; int c = 0; int i = 0; int j = 0; int k = 0; while( answer!=0) //start of while loop condition to execute unless equal to 0 { cout << "How do you like your eggs in the morning? " << endl; //writes to std o/p cout << "Enter 1 for scrambled, 2 for fried or 3 for poached, 0 to exit " << endl; //prompts user for i/p cin >> answer; //stores i/p from user if (answer == 1 ) //if 1 is selected increments a by 1 { a+=1; } else if (answer == 2) //if 2 is selected increments b by 1 { b+=1; } else if (answer == 3) //if 3 is selected increment c by 1 { c+=1; } } for (i = 0; i < a; i++) //initialises i at 0, loop commences compares it with a, increments i by 1 { cout << "Scrambled eggs" << "*" << endl; //prints out tally result } for (j = 0; j < b; j++) //initialises j at 0, loop to commence if b is greater than j, increments j by 1 { cout << "Fried Eggs " << "*" << endl; //prints out tally result } for (k = 0; k < c; k++) //initialises j at 0, loop commences if c is greater than a, increments j by 1 { cout << "Poached Eggs" << "*" << endl; //prints out tally result } } for(i=0;i

Loops 编程理货系统C++;还显示结果的条形图 #include//include头文件 #包括 使用名称空间std; int main()//主体fcn { int-answer;//删除整数并初始化它们 int a=0; int b=0; int c=0; int i=0; int j=0; int k=0; while(answer!=0)//开始执行while循环条件,除非等于0 { 不能替换这部分代码: #include <iostream> //include header files #include <string> using namespace std; int main () //main body fcn { int answer;//delcaring integers and initializing them int a = 0; int b = 0; int c = 0; int i = 0; int j = 0; int k = 0; while( answer!=0) //start of while loop condition to execute unless equal to 0 { cout << "How do you like your eggs in the morning? " << endl; //writes to std o/p cout << "Enter 1 for scrambled, 2 for fried or 3 for poached, 0 to exit " << endl; //prompts user for i/p cin >> answer; //stores i/p from user if (answer == 1 ) //if 1 is selected increments a by 1 { a+=1; } else if (answer == 2) //if 2 is selected increments b by 1 { b+=1; } else if (answer == 3) //if 3 is selected increment c by 1 { c+=1; } } for (i = 0; i < a; i++) //initialises i at 0, loop commences compares it with a, increments i by 1 { cout << "Scrambled eggs" << "*" << endl; //prints out tally result } for (j = 0; j < b; j++) //initialises j at 0, loop to commence if b is greater than j, increments j by 1 { cout << "Fried Eggs " << "*" << endl; //prints out tally result } for (k = 0; k < c; k++) //initialises j at 0, loop commences if c is greater than a, increments j by 1 { cout << "Poached Eggs" << "*" << endl; //prints out tally result } } for(i=0;i,loops,for-loop,nested,Loops,For Loop,Nested,如果在相应的for循环之前显示类型,会怎么样: cout << left << setw(20) << "Scrambled eggs " << right; for (i = 0; i < a; i++) //initialises i at 0, loop commences compares it with a, increments i by 1 { cout << "*"; //prints ou

如果在相应的for循环之前显示类型,会怎么样:

cout << left << setw(20) << "Scrambled eggs " << right;
for (i = 0; i < a; i++) //initialises i at 0, loop commences compares it with a, increments i by 1
    {
        cout << "*"; //prints out tally result
    }
cout << endl << left << setw(20) << "Fried Eggs " << right;
    for (j = 0; j < b; j++) //initialises j at 0, loop to commence if b is greater than j, increments j by 1
    {
      cout << "*"; //prints out tally result
    }
cout << endl << left << setw(20) << "Poached Eggs " << right;
    for (k = 0; k < c; k++) //initialises j at 0, loop commences if c is greater than a, increments j by 1
    {
            cout << "*"; //prints out tally result
    }
cout << endl;

您能显示所需的输出吗?与@still-a-Kid同时发布,以与您的代码类似的方式进行计算,只是我没有使用制表符格式。下次将注意到这一点。谢谢您的帮助
cout << left << setw(20) << "Scrambled eggs " << right;
for (i = 0; i < a; i++) //initialises i at 0, loop commences compares it with a, increments i by 1
    {
        cout << "*"; //prints out tally result
    }
cout << endl << left << setw(20) << "Fried Eggs " << right;
    for (j = 0; j < b; j++) //initialises j at 0, loop to commence if b is greater than j, increments j by 1
    {
      cout << "*"; //prints out tally result
    }
cout << endl << left << setw(20) << "Poached Eggs " << right;
    for (k = 0; k < c; k++) //initialises j at 0, loop commences if c is greater than a, increments j by 1
    {
            cout << "*"; //prints out tally result
    }
cout << endl;
cout << endl << "Scrambled eggs : \t";
for (i = 0; i < a; i++)
{
    cout << "*";
}

cout << endl << "Fried eggs : \t";
for (j = 0; j < b; j++)
{
    cout << "*";
}

cout << endl << "Poached eggs : \t";
for (k = 0; k < c; k++)
{
    cout << "*";
}
Scrambled eggs : ***
Fried eggs :     ******
Poached eggs :   ****