473,394 Members | 1,935 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,394 software developers and data experts.

initialization of 'fin' is skipped by 'case' label

Please! Help! This program was running at first but when I started to change the couts and cins to fouts and fins (in order for them to be save in a file directory), it shows a lot of errors such as:

initialization of 'fin' is skipped by 'case' label
'std::ifstream fin': redefinition

Here is the code of the program:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. struct file{
  7.     int fnum;
  8.     char fname[50], lname[50];
  9.     char cnum[50];
  10.     int balance, total;
  11. };
  12.  
  13. file f;
  14. //int i, list,ans, searchnum, delnum, x, y;
  15. int ans, list, i, searchnum, delnum, y;
  16. int cons, es, minsur, majsur;
  17. char others[50], name[50], yon, noy;
  18. int pay, oprice, balpaid;
  19.  
  20. void newLine();
  21. void line(char, int);
  22. void filedirectory();
  23. void deletefile();
  24. void procedure();
  25. void addfile();
  26.  
  27.  
  28.  
  29. int main()
  30. {
  31.     /*ofstream fout;
  32.     fout.open("d:\\hayamieyecenter.txt");*/
  33.     int choice, list=1;
  34.     f.total=0;
  35.     while(1){
  36.         system("cls");
  37.     cout << endl;
  38.     cout << "Welcome to Hayami Eye Specialist Center";
  39.     cout << "\n" << endl;
  40.     line('=',40);
  41.     cout << "            1. Add New File            \n";
  42.     cout << "            2. Edit File              \n";
  43.     cout << "            3. Search File             \n";
  44.     cout << "            4. Delete File             \n";
  45.     cout << "            5. View Files              \n";
  46.     cout << "            6. Exit                \n";
  47.     line('=',40);
  48.     cout << endl;
  49.     cout << "What would you like to do? ";
  50.     cin >> choice;
  51.     switch (choice)
  52.     {
  53.         case 1: //file cannot be saved
  54.             FILE *fp;
  55.             fp=fopen("d:\\myfiles\\sample2.txt","w");
  56.             ifstream fin;
  57.             fin.open("d:\\hayamieyecenter.text");
  58.             system("cls");
  59.             //addfile();
  60.             cout << "ADD NEW FILE\n";
  61.             line ('-', 26);
  62.             cout << "Enter Patient Information:\n";
  63.             cout << "File Number " << setprecision(3) << list;
  64.             cout << "\nFirst Name: ";
  65.             fin.getline(f.fname,50);
  66.             fputs(f.fname,fp);
  67.             newLine();
  68.             cout << "Last Name: ";
  69.             fin.getline(f.lname,50);
  70.             cout << "Contact Number: ";
  71.             fin >> f.cnum;
  72.             cout << endl;
  73.             procedure();
  74.             //addfile();
  75.             break;
  76.         case 2:
  77.             ifstream fin;
  78.             fin.open("d:\\hayamieyecenter.txt");
  79.             system("cls");
  80.             cout << "EDIT FILE\n";
  81.             line ('-', 25);
  82.             cout << "Enter File # to Edit: ";
  83.             cin >> i;
  84.             //ofstream fout;
  85.             //fout.open("d:\\hayamieyecenter.txt");
  86.             newLine();
  87.             if (i=list)
  88.             {
  89.             cout << "Edit First Name: ";
  90.             fin.getline(f.fname,50);
  91.             cout << "Edit Last Name: ";
  92.             fin.getline(f.lname,50);
  93.             cout << "Edit Contact Number: ";
  94.             fin >> f.cnum;
  95.             cout << "Balance: " << f.balance << "\nEnter amount to be paid: ";
  96.             fin >> balpaid;
  97.             f.balance-=balpaid;
  98.             fin >> f.balance;
  99.             cout << "are there more transactions made (Y/N) ? " << endl;
  100.             cin >> yon;
  101.             if (yon =='y'||yon =='Y')
  102.                 procedure();
  103.             if (yon == 'n'||yon == 'N')
  104.                 break; 
  105.             }
  106.         break;
  107.         case 3:{
  108.             ofstream fout;
  109.         fout.open("d:\\hayamieyecenter.txt");
  110.         system("cls");
  111.             cout << "SEARCH FILE\n";
  112.             line ('-', 25);
  113.         cout << "1.First Name\n";
  114.         cout << "2.Last Name\n";
  115.         cout << "3.Contact Number\n";
  116.         cout << "Select a number to search: ";
  117.         cin >> searchnum;
  118.                         switch (searchnum){
  119.                                             case 1:
  120.                                 cout << "Enter First Name to be searched: ";
  121.                                 fin.getline(name,50);
  122.                                 /*for (int a=0;a<=list;a++)
  123.                                 {*/
  124.                                     if (name == f.fname)
  125.                                     {
  126.                                 fout << endl;
  127.                                 fout << "  " << list << setw(15);
  128.                                 fout << f.fname << setw(25);
  129.                                 fout << f.lname << setw(25);
  130.                                 fout << f.cnum;
  131.                                 /*}*/
  132.                                 }
  133.                                 break;
  134.                                             case 2:
  135.                                 fout << "Enter Last Name to be searched: ";
  136.                                 fin.getline(name,50);
  137.                                 /*for (int a=0;a<=list;a++)
  138.                                 {*/
  139.                                 if (name == f.lname)
  140.                                 {
  141.                                 fout << endl;
  142.                                 fout << "  " << i + 1 << setw(15);
  143.                                 fout << f.fname << setw(25);
  144.                                 fout << f.lname << setw(25);
  145.                                 fout << f.cnum;
  146.                                 }
  147.                                 //}
  148.                                 break;
  149.                                         case 3:
  150.                                 fout << "Enter Contact Number to be searched: ";
  151.                                 fin.getline(name,50);
  152.                                 /*for (int a=0;a<=list;a++)
  153.                                 {*/
  154.                                 if (name == f.cnum)
  155.                                 {
  156.                                 fout << endl;
  157.                                 fout << "  " << i + 1 << setw(15);
  158.                                 fout << f.fname << setw(25);
  159.                                 fout << f.lname << setw(25);
  160.                                 fout << f.cnum;
  161.                                 }
  162.                                 //}
  163.                                 break;
  164.                                         default:
  165.                                 fout << "Invalid choice";
  166.                                 system("pause>0");
  167.                                 }
  168.                         break;}
  169.         case 4: //not yet fixed but claiming for fin
  170.             {deletefile();
  171.             break;}
  172.         case 5: //NOT YET FIXED BUT CLAIMING FOR FIN
  173.             {filedirectory();
  174.             system("pause>0");
  175.             break;}
  176.         case 6:
  177.             exit(1);
  178.         default:
  179.             cout << "Invalid choice, please try again: ";
  180.             system("pause>0");
  181.     } //choice
  182.     } //while(1)
  183. } //int main()
  184.  
  185. void procedure()
  186. {
  187.     ifstream fin;
  188.     fin.open("d:\\hayamieyecenter.txt");
  189.     cons = 3000;
  190.     es = 4000;
  191.     minsur = 60000;
  192.     majsur = 800000;
  193.     cout << "1. Consultation\n";
  194.             cout << "2. Eye Screening\n";
  195.             cout << "3. Minor Surgery\n";
  196.             cout << "4. Major Surgery\n";
  197.             cout << "5. Others\n";
  198.             cout << "Select a Procedure: ";
  199.             cin >> ans;
  200.             switch (ans){
  201.             case 1:
  202.                 cout << "Price: " << cons;
  203.                 f.total+=cons;
  204.                 break;
  205.             case 2:
  206.                 cout << "Price" << es;
  207.                 f.total+=es;
  208.                 break;
  209.             case 3:
  210.                 f.total+=minsur;
  211.                 cout << "Price" << minsur;        
  212.                 break;
  213.             case 4:
  214.                 f.total+=majsur;
  215.                 cout << "Price" << majsur;
  216.                 break;
  217.             case 5:
  218.                 cout << "Please Enter the desired procedure: ";
  219.                 fin.getline(others,50);
  220.                 cout << "Price: ";
  221.                 fin >> oprice;
  222.                 f.total+=oprice;
  223.             default:
  224.                 cout << "Invalid choice";
  225.                 system("pause>0");
  226.             }
  227.  
  228.             cout << "\nTotal Price:" << f.total << endl;
  229.             cout << "Payment: ";
  230.             fin >> pay;
  231.             if (pay < f.total) {
  232.                 f.balance+=f.total-pay;
  233.                 //fputc(f.balance,);
  234.             }
  235. } //procedure()
  236.  
  237. void filedirectory()
  238. {
  239.             ofstream fout;
  240.             fout.open("d:\\hayamieyecenter.txt");
  241.             system("cls");
  242.             cout << "FILE DIRECTORY\n";
  243.             line ('-', 80);
  244.             system("COLOR 5");
  245.             cout << "File No." << setw(15)
  246.             << "First Name" << setw(25)
  247.             << "Last Name" << setw(25)
  248.             << "Contact No."
  249.             <<endl;
  250.             line('-', 80);
  251.  
  252.             fout.setf(ios::fixed);
  253.             fout.setf(ios::showpoint);
  254.             fout.precision(2);
  255.  
  256.             /*for (int x=0; x < list; x++){*/
  257.             fout << endl;
  258.             fout << "  " << i + 1 << setw(15);
  259.             fout << f.fname << setw(25);
  260.             fout << f.lname << setw(25);
  261.             fout << f.cnum << endl;
  262.             fout << "Transaction: " << setw(40);
  263.             fout << f.total << setw(15);
  264.             fout << "Balance: " << f.balance;
  265. } // filedirectory
  266.  
  267. void deletefile()
  268. {
  269.         ifstream fin;
  270.         fin.open("d:\\hayamieyecenter.txt");
  271.         system("cls");
  272.             cout << "DELETE FILE\n";
  273.             line ('-', 25);
  274.     bool is_ok = false;
  275.     while(! is_ok)
  276.     {
  277.     cout << "\nSelect a file number to delete: ";
  278.     cin >> delnum;
  279.  
  280.     if (delnum > list)
  281.         cout << "The file number does not yet exist";
  282.     else
  283.         break;
  284.     }
  285.         //y = delnum -1;
  286.             delnum = list;
  287.             fin.clear();
  288.             fin.ignore();
  289.             cout << endl;
  290.             cout << "  " << list << setw(15);
  291.             cout << f.fname << setw(25);
  292.             cout << f.lname << setw(25);
  293.             cout << f.cnum;
  294.             cout << "Are you sure (Y/N)? ";
  295.             cin >> noy;
  296.             if (noy == 'y' || noy == 'Y')
  297.             {
  298.                 //for (int x=y; x<list; x++)
  299.                 //{
  300.                 //    /*f.fname = f[list+1].fname;
  301.                 //    f[list].lname = f[x+1].lname;
  302.                 //    f[x].cnum = f[x+1].cnum;
  303.                 //    f[x].balance = f[x+1].balance;
  304.                 //    f[x].total =  f[x+1].total;*/
  305.                 //}
  306.                 --list;
  307.  
  308.                 /*for (int x = 0; x <list; x++)
  309.                 {
  310.                     fout << f[x].fname << "," <<f[x].lname << "," << 
  311.                 }*/
  312.             }
  313.  
  314.         system("pause>0");
  315. } //deletefile()
  316.  
  317. void addfile()
  318. {
  319.     ofstream fout;
  320.     fout.open("d:\\hayamieyecenter.txt");
  321.     list++;
  322. } //addfile
  323.  
  324.  
  325. void line(char ch, int ctr)
  326. {
  327.     for (int i = 0; i < ctr; i++) {
  328.         cout << ch;
  329.     }
  330.     cout << endl;
  331. }
  332.  
  333. void newLine()
  334. {
  335.     char s; do{
  336.         cin.get(s);
  337.     } while (s != '\n');
  338. }
  339.  
It'll be a lot of help. thank you so muchhhhh!!! ^_^
Jan 28 '15 #1
1 2927
weaknessforcats
9,208 Expert Mod 8TB
The variable fin is defined in case 2 but you use it in case 1.

You will need to move the definition of fin so it is visible to all the cases.
Jan 28 '15 #2

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

Similar topics

11
by: Neil Zanella | last post by:
Hello, Does anyone know what the following g++ compiler error message means: error: jump to case label I get this error when switching two case labels together with their bodies. I have no...
8
by: JKop | last post by:
g++ test.cpp -ansi -pedantic -o test.exe test.cpp: In function `int main()': test.cpp:22: case label does not reduce to an integer constant Why won't "operator unsigned int() const" do its job...
29
by: SysSpider | last post by:
Hi again, This is my problem: when i try to compile the code that contains the function below, i get this: -- gcc:21: error: case label does not reduce to an integer constant gcc:24: error:...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
3
by: newguy194 | last post by:
I am currently writing a Win32 application and when I compile I get a "Jump to case label" error and another error tellling me that switch(LOWORD(wParam)) is unreachable in the switch, when I remove...
4
by: clairelee0322 | last post by:
My program has an error C2360: initialization of 'i' is skipped by 'case' label. I don't know why. Please help me out! thks!! the error occurs in Division case 3. //Claire's Calculator...
5
by: Rex Mottram | last post by:
Can anyone explain this? % cat t.c #include <stdio.h> #define FIRST "first" #define SECOND "second" int main(int argc, char *argv)
2
mnf7
by: mnf7 | last post by:
My program has an error C2360: initialization of 'c' is skipped by 'case' label. I don't know why. Please help me out! thks!! the error occurs in main(case 2 & case 3) ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.