473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Basic Code not working

So what I am trying to do is write a simple program with a main menu where the user will be able to fill in the details of a project,list all projects, delete a chosen project or exit the program. Projects will be saved in an array. The functions will use structures.

I have written a functional code which compiles fine(big deal lol i know) but thus far only the 4th option "exit" works. The other 3 choices seem to not be working.

Here's my code

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h> 
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct fullname
  6. {
  7.         char name[10];
  8.         char surname[10];
  9. };
  10. struct meletes
  11. {
  12.         int identifier;
  13.         struct fullname customer;
  14.         char date[10];
  15.         float price;
  16. };
  17. void initialize(struct meletes projects[10]);
  18. struct meletes newp(struct meletes projects[10]);
  19. struct meletes list(struct meletes projects[10]);
  20. struct meletes deletep(struct meletes projects[10]);
  21.  
  22. int main(void)
  23. {
  24. int choice,k;
  25. struct meletes projects[10];
  26.  
  27. void initialize(struct meletes projects[10]);
  28.  
  29. printf("Main Menu\n ========\n");
  30. printf("Please choose a function from below:\n");
  31. printf("1.New Project\n2.Delete\n3.List\n4.Exit\n");
  32. scanf("%d", &choice);
  33.  
  34.     while ((choice != 1) && (choice != 2) && (choice != 3) && (choice != 4))
  35.           {
  36.  
  37.            printf("You have chosen a wrong function, please use numbers 1-4:\n\n");
  38.            printf("Main Menu\n ========\n");
  39.            printf("Please choose a function from below:\n");
  40.            printf("1.New Project\n2.Delete\n3.List\n4.Exit\n");
  41.            scanf("%d", &choice);
  42.            }
  43.  
  44.           while (choice != 4)
  45.           {
  46.           switch (choice) {
  47.  
  48.                  case 1:
  49.                  {
  50.                   struct meletes newp(struct meletes projects[10]);
  51.  
  52.                   }
  53.  
  54.                  case 2:
  55.                  {
  56.                   struct meletes deletep(struct meletes projects[10]);
  57.  
  58.                   }
  59.  
  60.                  case 3:
  61.                  {
  62.                   struct meletes list(struct meletes projects[10]);
  63.  
  64.                  }
  65.                          }
  66.  
  67.  
  68.             printf("Main Menu\n ========\n");
  69.             printf("Please choose a function from below:\n");
  70.             printf("1.New Project\n2.Delete\n3.List\n4.Exit\n");
  71.             scanf("%d", &choice);             
  72.  
  73.           }        
  74.  
  75.           printf("Thank u.\n");
  76.  
  77. system("pause");
  78. return 0;
  79. }
  80.  
  81. void initialize(struct meletes projects[10])
  82. {
  83. int l;
  84.  for(l=0; l<10; l++)
  85.   {
  86.           projects[l].identifier = 00000;
  87.           projects[l].price = 0.00;
  88.           strcpy(projects[l].customer.name,"----------");
  89.           strcpy(projects[l].customer.surname,"----------");
  90.           strcpy(projects[l].date, "0/0/0");
  91.   }          
  92. }          
  93.  
  94. struct meletes newp(struct meletes projects[10])
  95. {
  96.         int i;
  97.         for(i=0; i<10; i++)
  98.         {
  99.                  if (projects[i].identifier == 00000)
  100.                  {
  101.                     scanf("Please enter the project's identifier %d\n", &projects[i].identifier);
  102.                     scanf("Name:%s\n", &projects[i].customer.name);
  103.                     scanf("Surname:%s\n", &projects[i].customer.surname);
  104.                     scanf("Give the date in dd/mm/yyyy! format :%c\n", &projects[i].date);
  105.                     scanf("Price:&f\n", &projects[i].price);
  106.                  }
  107.              break;
  108.         }                
  109.  
  110. }
  111.  
  112. struct meletes deletep(struct meletes projects[10])
  113. {
  114.        int j,id;
  115.         for (j=0; j<10; j++)
  116.         {
  117.             if (projects[j].identifier != 00000)     //Emfanizei oles tis meletes pou den ine diegrammenes
  118.                {
  119.                printf("%d\n", projects[j].identifier);
  120.                }
  121.         }
  122.  
  123.         scanf("\nPlease insert the identifier of the project u want to delete:%d", &id);
  124.  
  125.         for(j=0; j<10; j++)
  126.         {                       
  127.           projects[j].identifier = 00000;
  128.           projects[j].price = 0.00;
  129.           strcpy(projects[j].customer.name,"----------");
  130.           strcpy(projects[j].customer.surname,"----------");
  131.           strcpy(projects[j].date, "0/0/0");
  132.         }
  133.  
  134. }
  135.  
  136. struct meletes list(struct meletes projects[10])
  137. {
  138.        int k;
  139.         for(k=0; k<10; k++)
  140.         {
  141.                  if (projects[k].identifier != 00000); 
  142.                     {
  143.                     printf("         Project %d:", k);
  144.                     printf("\nIdentifier:%d\n", projects[k].identifier);
  145.                     printf("Name:%s\n", projects[k].customer.name);
  146.                     printf("Surname:%s\n",projects[k].customer.surname);
  147.                     printf("Date:%s\n", projects[k].date);
  148.                     printf("Price:%d\n", projects[k].price);
  149.                     }
  150.         }
  151.  
  152. }        
Any ideas will be really appreciated
May 10 '12 #1
1 1388
weaknessforcats
9,208 Expert Mod 8TB
It looks like you are missing break statements at the end of each of the cases in your switch.

There may be other stuff but I didn't look that far.
May 11 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andreas Klemt | last post by:
Hello, for what is the LABEL good when programming in visual studio like this: Sub xxxx Label1: xxxx xxxx xxx
4
by: Chris Strug | last post by:
Hi there, Possibly something of a simple question but I was wondering is anyone could provide a few pointers or links. Given that I have two forms, a main (frmMain) and a child (frmChild)....
2
by: sbweld | last post by:
Hello, I am using Powerpoint 2007 and have found an option to integrate visual basic code into the slides. I am building a standalone Kiosk and I want my powerpoint presentation to reset and go...
1
by: AMK2701 | last post by:
Hi, I am just new at using this code, so have probably made a really simple mistake. My code works fine just in the sub form I created it, but when putting the sub form in the main form, the code...
1
by: suneel271 | last post by:
code working in internet explorer but not in mozilla and iam getting erroe like window.event has no properties and here is the code <%@ page language="java" contentType="text/html;...
3
by: kepskp | last post by:
i just write code for select option in combo box which i m select but when i press search button and then click on back button then there in no option selected. and that same code working in ie7 and...
3
by: bbatson | last post by:
New to visual basic; trying to teach myself. Here is very basic code I am using to try to fill a text box on my form after updating a box that selects an employee ID. Dim strsql As String strsql...
4
by: raaman rai | last post by:
guys, what is the idea to backup sql server databse via visual basic code. And i also want the code please.
2
by: paliko | last post by:
a Visual basic code for an online tax payment system
1
by: vinayreddy | last post by:
How to see visual basic code of ms access file inorder to change the path of the database resides. Please any body can provide solution for this.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.