Just making typical console game where hero moves with w a s d.
However, in my code, while a and w work (minusing), s and d dont work (adding). I have used a switch statement to change the char position of the hero based on kbhit.When you hit s or d, the buttons that add 1 to the 2nd dimension of the array, the screen goes crazy!
#include <iostream>
#include <string>
#include <conio.h>
#include <ctime>
#include <cstdlib>
using namespace std;
const char PLAYER = 'H';
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.
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)
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?
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.
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: " << "
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.
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 ....
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:
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.
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.
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?
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]);
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
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.
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;
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!