C++ :: Returning Operator To Switch Statement
Sep 5, 2012
I planned to build a four function fraction calculator adding some advance feature like error checking in input so that user are prompted to input correct numbers and operator.
I created a separate member function getOper() function for getting correct operator and getFrac() function for getting correct fraction.
My intention was just to get correct operator from getOper() function and returning the operator to switch in main() function to do specific calculation. But, i don't know why i am getting repeatedly error when inputting correct operator while debugging program.
Here's my complete code.
Code:
#include <iostream>
using namespace std;
char c;
class fraction {
private :
int num;
[Code] .....
I checked the program again by assigning char to variable "oper" and function "getOper(). But, result is same.And again i changed variable "oper" to default keyword operator, but, it really didn't worked as expected.
View 6 Replies
ADVERTISEMENT
Mar 21, 2015
My code is supposed to read a five to four digit code of a resistor from a file and determine the resistor's nominal, lower and upper tolerance values. I have inputted my file's first resistor code as a string so I could run tests on it but the problem that occurs is that a get the wrong values from my switch-case statements. I have put printfs after the function call to see what the values were and they turned out wrong. If I could get my return values to be right then I could be on my way coding.
#include<stdlib.h>
#include<stdio.h>
double bandNum(char x); // function prototype that will read the resistor value for the first, second and possibly third band
double bandMult(char x); // function prototype that multiplies the resistor by some value of 10
double bandTol(char x); // function prototype that the tolerance of the resistor is multiplied by
[Code] ....
View 5 Replies
View Related
Sep 7, 2013
How to make if else code below into SWITCH STATEMENT?
cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;
[Code]....
View 6 Replies
View Related
Mar 6, 2013
I was wondering how you would put this if else statement to a switch statement.
void PlayerDB::AddPlayer(const Player& avatarPlayer) {
char * playerName = new char[avatarPlayer.lenName()];
Player*player = NULL;
[Code] ....
View 1 Replies
View Related
Aug 16, 2014
okay so like case 2 and 3 is not working, also the program is still not finish but why isn't case 2 and 3 not functioning well on the switch part? case 1 works just fine
Code:
#include<stdio.h>
main ()
{
//passcode part (passcode is 1234)
[Code].....
View 5 Replies
View Related
Apr 15, 2014
so I am trying to have an switch statement array. but every time i complete a case statement the whole process is returned. the thing is i want the menu to stay up even if i complete the case.
View 2 Replies
View Related
Aug 8, 2014
The sample output of this program would be:
Please select:
1 - Year
2 - Day
3 - Month
Input choice: 1
Input Number: 2
I'm a Sophomore!
Please select:
1 - Year
2 - Day
3 - Month
Input choice: 2
Input Number: 2
It's Tuesday.
Please select:
1 - Year
2 - Day
3 - Month
Input choice: 3
Input Number: 2
February. Heart's month!
Here is my code, I only typed the Year(levels) yet because when I tried to input 2(day) and 3(month) for the Input choice and after that, Inputting a number to 1-4 would yield the same result to case 1's year levels.
#include <stdio.h>
#include <conio.h>
using namespace std;
[Code].....
how to link the case 2 to days and case 3 to months?
View 1 Replies
View Related
Sep 17, 2014
I have a problem with the switch statement because it doesn't prompt me to input something.
#include <iostream>
#include <fstream>
#include<cstring>
using namespace std;
//Compiler: Dev C++ and cygwin
void rd() {
string txt;
[Code] ....
I want to get rid of this kind of output ...
View 5 Replies
View Related
Oct 8, 2014
if( vehicleUse == 'C' ) // Carpool
{
// TODO: Convert to a switch statement
if( vehicleLoad == 'E' ) // 6-8
cout << "Ford Windstar" << endl;
else if( vehicleLoad == 'F' ) // 8-10
[Code] .....
View 1 Replies
View Related
Sep 23, 2013
is it possible to compare value in switch statement? i.e: a > b
View 5 Replies
View Related
Nov 1, 2013
I am using a switch statement as a menu. If I enter a non-integer value as my choice, I expect the error message , "Invalid entry", to display but instead the output keeps running.
View 2 Replies
View Related
Mar 21, 2014
Right now I have to use seekg to read a letter from a text document then using a switch statement i have to show what that letter is
#include <iostream>
#include <fstream>
#include <math.h>
#include <time.h>
[Code]....
View 7 Replies
View Related
Jan 16, 2014
I was getting errors and I looked into the error and it told me to fix it by adding Code: { } in my case statements. I did, it compiled but fell through the whole thing. Lets say I enter 1, it outputs the was not found 5 times in a row.
Code:
void addressbook::EditNameOrDate() {
std::cout << "Enter 1 to Edit the contacts First Name: " << "
";
std::cout << "Enter 2 to Edit the contacts Last Name: " << "
";
std::cout << "Enter 3 to Edit the contacts Street Address: " << "
[Code] .....
View 8 Replies
View Related
Jun 12, 2013
I pretty much got the assignment done. All it asked for was that you make a C program that displays which manufacturer owned a disk drive based on the code entered. Pretty simple. Just enter 1, 2, 3, or 4 and get the associated manufacturer. Though I am trying to implement an error messege to it for any interger that isn't 1-4.
Code: #include <stdio.h>
int main()
{
[Code]...
o errors are given and it works fine as long as you enter 1-4, but when you enter any other didgit it just stops the program without any messeges.
View 5 Replies
View Related
Feb 11, 2013
Im going through a C tutorial and im going to create a Database as part of the course. Im just in the very beginning of the project so its a very simple program so far.
Code:
#include<stdio.h>
main(){
/*Variabler for att lagra information om skiva*/
char title[200];
char artist[100];
int tracks;
int price;
[Code] ....
The first switch case statement takes me to the menu of choice, 1 or 2. However, chosing menu option one and trying to input a title or artist name, the program crashes.
Next, going into menu option 2 and then trying to print out, for example, title nothing happend. The process just ends.
Again, im sure this simple prototype is full of errors ....
View 1 Replies
View Related
Nov 6, 2014
I'm creating a program that is combining functions to show a menu to a user then the user picks numbered items which results in the totalling of a bill for them.
Where I'm stuck is after they're entered their selections, how to take them and sum them up. I've been trying with a switch statement, but I'm not sure if this is the right method. Is it even possible to sum separate cases of a switch statement together? Below is the code I've gotten so far:
#include <iostream>
#include <iomanip>
using namespace std;
void showMenu ();
void showBill (double, double, float, double);
void changeDue (double, int);
[Code] ....
View 3 Replies
View Related
May 28, 2014
I was just wondering if a switch statement can work without writing each case, for instance:
{ int age;
age=18;
while (age!=0) {
cout<<"Enter age :"<<endl;
cin>>age;
switch (age) {
[Code] ....
It works only for values specifically entered as a case, for instance if you enter 5 or 15 , it says bicycle, but if you enter anything inbetween it goes to default. Same with 18 and 100. It can't possibly be that you have to enter
case 19:
case 20:
case 21:
case 22:.......up to 100 to include all possible cases.
View 7 Replies
View Related
Feb 23, 2015
I had it working with the switch statement within the function, but later instructions said that it must be inside of main. I just get a loop no matter what I do. 5 needs to exit the program, all the other selections need to display the corresponding cout statements. I've done something to where the inputs are not actually passing into the switch statement. If any value other than 1-5 is put in, the menu should repeat and prompt the user again.
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int call_menu(int selection);
double kilo_m(double miles);
[Code] .....
View 2 Replies
View Related
Feb 14, 2014
Suppose you have a switch statement defined like:
switch (parameter) {
case ONE:
case TWO:
// ... other n-2 cases
case N:
doSomething();
break;
default:
somethingElse();
break;
}
What is the complexity of the doSomething()? Is it still equal to the complexity of doSomething() , or the complexity of doSomething() plus the number of case statements? In other words, does the number of case statements a conditional piece of code has count towards the complexity?
View 10 Replies
View Related
Feb 26, 2014
The program i am trying to make is for practice of using switch. the idea is the user enters a number and the program will print a day of the week corresponding to said number.
the statement is not complete with all cases yet, but i dont want to write all of it until i am sure of it being correct.
errors when compiling (gcc) are as follows
1 warning and 3 errors generated.
Robins-MacBook-Air:array2 RDenton$ gcc array2.c
array2.c:26:9: warning: format string is not a string literal
(potentially insecure) [-Wformat-security]
printf(a[uservalue]);
[code]....
View 3 Replies
View Related
Nov 22, 2014
The switch statement is giving me trouble. Worked fine in the main, but when I had to put it in separate functions per my professor, I had several issues. I guessing I am not calling the function correctly. Our group worked on it but could not find a solution to fix the switch statement.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h>
using namespace std;
//function prototypes
int menu(); //function to show main menu
void Seating_Chart(); //function to show seating chart
[Code] ....
View 2 Replies
View Related
Aug 17, 2012
I'm using a dev c++ bloodshed compiler. How can we write a menu using switch statement?
View 1 Replies
View Related
May 10, 2012
How can we use switch statement 2 times in a program?
View 2 Replies
View Related
Mar 22, 2013
How to put my all assignment questions that are 6 in number in one program by using switch statement ?
so if a user wants to see any question by choice!
View 1 Replies
View Related
Jul 26, 2012
I have a question related to switch statement, which the switch in class employee2 gives me error at output. Program compiled well. I am using Code::Block Compiler V10.5. I have created object of class employee2 in main() function to get data from user, store it and display it. At the output, Compiler doesn't show actual output what i am expecting. The fun thing is my compiler printed emocion like (), where (hourly/monthly/weekly) was supposed to print.
Code:
#include <iostream>
using namespace std;
enum period {hourly,weekly,monthly};
class employee2 {
private :
char ch;
period x;
double compensation;
[Code] ....
View 10 Replies
View Related
Sep 20, 2013
how to re-prompt a user with a switch statement menu that I prompted them earlier with. There are 4 options and after the user chooses an option the menu is supposed to pop up again unless the user chooses option 4, how do I do this? For reference I'll put up my source code.
Code:
int main(){
int init_bal,choice,balance,investment, donation;
printf("Welcome!
[Code]....
View 2 Replies
View Related