|
-
February 9th, 2009, 05:35 PM
#1
I finished my project, but I have two bugs, help please
Goal of project: create a menu system so I can intergrate all current and future labs
problem: my prelab 0, which ask for basic user inputs, and relaying that information, is skipping the first question. it works fine by itself in its own main program. my second problem is that I'm not writing the exiting code right. I can exit fine if I choose exit as my first option but if I choose exit after using the program, it wont exit.
I'm using VS 2008 C++
Code:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include "iostream"
#include <string>
void lab_1(void);
void menukeys(void);
#pragma once
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <stdafx.h>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
void lab_1(void) //this is actually lab0
{
cout << "Enter Your Name: ";
string name;
getline(cin, name);
cout << "Enter Your Email Address: ";
string email;
getline(cin, email);
cout << "Enter Your Telephone Number: ";
string phone;
getline(cin, phone);
cout <<endl;
cout << name << "\n" << email << "\n" << phone << endl << "\n";
}
#include "stdafx.h"
using namespace std;
void menukeys(void) //this is lab1
{
int select;
char next;
cout << "ECET344 Laboratory Project Menu\n0. Pre-Lab std I/O\n1. Lab 1 The Menu\n2. Lab 2 is Under Construction\n3. Lab 3 is Under Construction\n4. Lab 4 is Under Construction\n5. Lab 5 is Under Construction\n6. Lab 6 is Under Construction\n7. Lab 7 is Under Construction\n8. Lab 8 is Under Construction\n9. Lab 9 is Under Construction\nq. to terminate the project program\n";
cin >> select;
while (select <10)
{
switch (select)
{
case 0:
{
lab_1();
cout << "Press any key to continue";
cin >> next;
menukeys();
break;
}
case 1:
{
menukeys();
break;
}
case 2:
{
cout << "Lab 2 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
case 3:
{
cout << "Lab 3 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
case 4:
{
cout << "Lab 4 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
case 5:
{
cout << "Lab 5 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
case 6:
{
cout << "Lab 6 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
case 7:
{
cout << "Lab 7 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
case 8:
{
cout << "Lab 8 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
case 9:
{
cout << "Lab 9 is not ready \n\n";
cout << "Enter any key to continue: ";
cin >> next;
menukeys();
break;
}
default:
{
cout << "Good BYE!\n";
select = 10;
break;
}
}
}
}
#include "stdafx.h"
#include "iostream"
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) //this is the main
{
menukeys();
return 0;
}
#include "stdafx.h"
-
February 9th, 2009, 05:36 PM
#2
Re: I finished my project, but I have two bugs, help please
a lot of the headers seems to be repeated... should I delete some of them?
Edit: ok so I fixed the exit problem by using "exit(1)"
so... why is it skipping my first cin when my prelab is called? this sounds like a simple fix
Last edited by jd53887; February 9th, 2009 at 06:13 PM.
-
February 9th, 2009, 06:10 PM
#3
Re: I finished my project, but I have two bugs, help please
You only need to insert a header once, and normally you do this at the top of your file.
-
February 9th, 2009, 06:25 PM
#4
Re: I finished my project, but I have two bugs, help please
By the same token it doesn't hurt to repeat headers. Don't get caught up in the desire to arrange things to minimize header inclusion duplication. It's always better to include a header twice than not at all, remember.
-
February 9th, 2009, 06:25 PM
#5
Re: I finished my project, but I have two bugs, help please
these are multiples files taken from the "Header Files" and the "Source Files"
the program wont work if I take some of the headers out, even the repeated ones.
-
February 9th, 2009, 07:48 PM
#6
Re: I finished my project, but I have two bugs, help please
ok obviously, something is filling in the first cin of hte lab1.cpp, so I decided I'm just going to insert another cin to overwrite that first cin that gets skipped.
i didnt solve the problem, i merely patched it
-
February 9th, 2009, 09:23 PM
#7
Re: I finished my project, but I have two bugs, help please
Very good! If you can identify that issue----which comes up here *all* the time----you might just have a future in this.
The problem is that at some point prior to the getline() call, a normal cin >> var statement was executed. The user probably pressed return after entering their text, but the newline that resulted from that didn't end up in a variable---it's just hanging out in the cin stream. It would be automatically discarded if another cin >> var statement were encountered, since those skip whitespace anyway.
But getline() is different. It reads until it encounters a newline, and doesn't discard whitespace. As a result, the first getline() call returns immediately, doing nothing *except* extracting that lingering whitespace from the stream.
The common solution is to use cin.ignore() (check the documentation) to discard any lingering newlines before calling getline(). You don't need to do it if the last input operation was also a getline().
-
February 11th, 2009, 01:42 AM
#8
Re: I finished my project, but I have two bugs, help please
ahhh... ur a genius.
i just typed it in, and it worked perfectly.
they should have a rep button.
-
February 11th, 2009, 10:14 AM
#9
Re: I finished my project, but I have two bugs, help please
 Originally Posted by jd53887
they should have a rep button.
and they do
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|