为什么我的循环不起作用

编程入门 行业动态 更新时间:2024-10-26 16:30:08
本文介绍了为什么我的循环不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么循环不起作用? 我正在为(;;)使用Indefinite for循环,但它不会停止循环 所以我尝试使用while循环,当它是时使用while循环 (bra> 2) 它仍然打印(您是否要添加更多y或n");我不希望这样做. 当(bra == 1)并要求Y或N时,它在Y或N处中断 以及如何调用我不希望程序退出的主要功能.休息后,我希望它返回到主要功能'' for循环dis是代码

why is the loops not working ? i am using an Indefinite for loop for (;;) but but it does not stop looping so i tride to use while loop and with the while loop when It is (bra>2) it still print ("do u want to add more y or n");which i do not want it to do so. and when ( bra ==1) and it ask for a Y or N it breaks at either Y or N And how do i call back the the main function i do not want the program to exit. after the break, i want it to go back to the main function'' with the for loop dis is the code

#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> void create_new_stock(void); void display_stock(void); void sales(void); void modify(void); void Additem(void); void Viewitems(void); void Viewcategory(void); void Editcategory(void); void Edititems(void); void Edit(void); void Deleteitem(void); void Deletecategory(void); void PrintBeeper(void); void CreateFile(void); void DeleteFile(void); void sel(); double u_prx = 0.0; double total=0.0; double G_total=0.0; double amut_b=0.0; double amut_u=0.0; double S_prx_Blk=0.0; double S_prx_u=0.0; double T_amut_blk=0.0; double T_amut_u =0.0; double qty_sold = 0.0; int T_qty_bulk =0; int T_qty_u =0; int G_T_qty_bulk=0; int G_T_qty_u=0; int qty_u= 0; int qty_left = 0; int qty_bulk = 0; char cate[20]; char iname[20]; char code[6]; void create_new_stock() { int bra; char ans; printf("Enter Category "); scanf("%s",cate); printf("How many brands do u want to add?"); scanf("%d",&bra); for(;;) { printf("Enter brand name"); scanf("%s",iname); printf("Enter Buying price(bulk)"); scanf("%lf",&amut_b); puts("Enter Quantity in bulk"); scanf("%d",&qty_bulk); puts("Enter Quantity of items (number of items in a box)"); scanf("%d",&qty_u); T_qty_u=qty_bulk*qty_u; T_amut_blk=amut_b/qty_u; puts("Enter Selling price for(box)"); scanf("%lf",&S_prx_Blk); puts("Enter selling price for unit"); scanf("%lf",&S_prx_u); if (bra<=1) puts("do u want to add more y or n"); scanf("%c",&ans); if(tolower(ans) == 'n') break; } getchar(); } void display_stock() { } void sales() { } void modify() { } int main() { char sele; // seletion of data puts(" Welcome to my sales Program"); puts("<1> \t Create a new stock "); puts("<2> \t Display Stock"); puts("<3> \t Sales"); puts("<4> \t Modify"); puts("<5> \t exit"); puts("Enter selection"); scanf("%c",&sele); switch (sele) { case '1': create_new_stock(); break; case '2': display_stock(); break; case '3': sales(); break; case '4': modify(); break; case '5': exit(1); break; } return 0; getchar(); }

在while循环中,这是代码

with the while loop this is the code

#include <stdlib.h> #include <ctype.h> #include <string.h> #include <ncurses.h> void create_new_stock(void); void display_stock(void); void sales(void); void modify(void); void Additem(void); void Viewitems(void); void Viewcategory(void); void Editcategory(void); void Edititems(void); void Edit(void); void Deleteitem(void); void Deletecategory(void); void PrintBeeper(void); void CreateFile(void); void DeleteFile(void); void sel(); double u_prx = 0.0; double total=0.0; double G_total=0.0; double amut_b=0.0; double amut_u=0.0; double S_prx_Blk=0.0; double S_prx_u=0.0; double T_amut_blk=0.0; double T_amut_u =0.0; double qty_sold = 0.0; int T_qty_bulk =0; int T_qty_u =0; int G_T_qty_bulk=0; int G_T_qty_u=0; int qty_u= 0; int qty_left = 0; int qty_bulk = 0; char cate[20]; char iname[20]; char code[6]; <pre> void create_new_stock() { int bra; char ans; int a=1; printf("Enter Category \n"); scanf("%s",cate); printf("How many brands do u want to add?\n"); scanf("%d",&bra); while((bra>a)||(bra>=a)) { printf("Enter brand name\n"); scanf("%s",iname); printf("Enter Buying price(bulk)\n"); scanf("%lf",&amut_b); printf("Enter Quantity in bulk\n"); scanf("%d",&qty_bulk); printf("Enter Quantity of items (number of items in a box)\n"); scanf("%d",&qty_u); T_qty_u=qty_bulk*qty_u; T_amut_blk=amut_b/qty_u; printf("Enter Selling price for(box)\n"); scanf("%lf",&S_prx_Blk); puts("Enter selling price for unit"); scanf("%lf",&S_prx_u); a++; puts("do u want to add more y or n"); scanf("%c",&ans); if(tolower(ans) =='Y') break; } } void display_stock() { } void sales() { } void modify() { } int main() { char sele; // seletion of data puts(" Welcome to my sales Program"); puts("<1> \t Create a new stock "); puts("<2> \t Display Stock"); puts("<3> \t Sales"); puts("<4> \t Modify"); puts("<5> \t exit"); puts("Enter selection"); scanf("%c",&sele); switch (sele) { case '1': create_new_stock(); break; case '2': display_stock(); break; case '3': sales(); break; case '4': modify(); break; case '5': exit(1); break; } return 0; getchar(); }

推荐答案

Brands bra是您询问要创建的用户的品牌数,a是已创建品牌的当前计数,您要在用户创建所需编号后退出循环; Brands bra is the number of brands you asked the user they want to create and a is the current count of the created brands, and you want to exit the loop when the user has created the required number so; while(a <= bra) { //the loop content a++; }

更多推荐

为什么我的循环不起作用

本文发布于:2023-11-06 13:24:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563803.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!