C++ :: Program Will Echo Letter (User Input) And Output Name Of The Day Of Week
Oct 21, 2012
Write a C++ program that does the following:
Prompt the user to enter a day of the week as M (or m), T, W, R, F, S, and U for Monday through Sunday respectively. The user may enter an upper or lower case letter.
When the user enters a character, the program will echo the letter and output the name of the day of the week.
Provide an error trap that reads something like "you have entered an invalid letter; program aborting." Suggestion: use a switch statement with the error trap as the default condition. it is not necessary to prompt for multiple inputs.
So I know how to get the program to echo back the letter and everything. What I am a little confused about is: will I have to define all the letters as their respective day? eg. make M== Monday. And if I do have to do that how would I get it to accept Upper and Lower case letters and recognize that that letter is == monday ect. ect.
Also my main problem is the switch statement as the error trap. I have never used the switch statement, but I know what they do. I just don't really understand how I would use it for an error trap. Am I suppose to just make a case for every other letter in the alphabet other then M T W R F S and U? Even if I do that then what if the user enters a number instead of a letter?
View 4 Replies
ADVERTISEMENT
Apr 3, 2013
I'm just starting coding and I just want it to input a date, then output a day of the week.
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int startday = 0, sm = 1, sd = 1, sy = 2000, cm = 0, cd = 0, cy = 0;
cout << "Please enter the current month, day, and year: ";
[Code] ....
View 1 Replies
View Related
Mar 11, 2014
The problem that I am having is that , the program outputs numbers that are perfect numbers and im not sure where i can add a statement to make it so that if it isn't a perfect number it doesn't output...
#include<iostream>// allows user input/output
#include<conio.h>
#include<fstream>//data file / result file
#include<iomanip>
#include<cmath> // math function
#define in_file "data.txt"
#define out_file "result.txt"
[Code] ....
View 3 Replies
View Related
Sep 22, 2013
I need to write a C program to make the user input some text,and the first letter of each word has to be uppercase.(have to use while loops)So for example lets say the user inputs:
i lOvE pRoGrAmMiNg
The output needs to be:
I Love Programming
Code:
#include <stdio.h>
int main()
{
int i = 0;
char c, lower_c;
printf("Enter text
");
[code]....
I have started this code by making the letters lowercase.I am not sure how proceed after this step, the step of making the first letter uppercase.
View 2 Replies
View Related
Oct 3, 2013
/*
* echoString2.c
* Echoes a string entered by user. Converts input to C-style string.
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(void) {
char aString[200];
char *stringPtr = aString;
[Code] ....
and these are my errors
212Untitled1.cpp[Error] stray '222' in program
212Untitled1.cpp[Error] stray '' in program
212Untitled1.cpp[Error] stray '222' in program
262Untitled1.cpp[Error] stray '222' in program
262Untitled1.cpp[Error] stray '' in program
262Untitled1.cpp[Error] stray '222' in program
Untitled1.cppIn function 'int main()':
2125Untitled1.cpp[Error] 'n' was not declared in this scope
View 3 Replies
View Related
Jul 17, 2013
I wanted to take the averages of the whole week and output a print statement. I've tired few ways this like assigning "temp" a pointer, or in each if statement assigning temp to a new variable like a, b , c etc. Then adding them all up at the end and dividing by 7. My issue is I am unclear how to store the number typed for each if statement while the program is running, then have it compute the simple equation. The code in question is below:
Code:
#include <stdio.h>
int main(int argc, const char * argv[]) {
int i, j = 0, temp = 0;
for (i=1; i<=7; i++) {
j++;
[Code] ....
View 1 Replies
View Related
Sep 9, 2014
I'm trying to write a program that takes input from the user (thats a char) and outputs it to the monitor in hex form.The program is meant to continuously take input from the user then output to the monitor in hex form until an EOF is detected this triggers the program to close.The following code does this except that I get a lower case 'a' at the end of each output.I think the 'a' has to do with the enter key and if that is the case how can i tell the program to ignore this input from the user.
Example: input from user: ABC output to monitor: 41 42 43 a
Code:
#include <stdio.h>
int main(void) {
char myChar;
while(EOF != (myChar = getchar())) {
printf("%x ",myChar);
}
system("pause");
return 0;
}
View 5 Replies
View Related
Apr 22, 2014
I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.
Code below:
#include <iostream>
#include <string>
using namespace std;
string arr[]={"one","two","three","four","five","six","seven","eight","nine"};
class convertTo{
public:
int signed num;
int convet(){
cout<<"Enter a number to convert to string "; cin>>num;
[code]....
View 2 Replies
View Related
Jan 14, 2015
So I'm supposed to write something that will output a multiplication table from two user input integers between 2 and 10.
For example it should display like this is the user inputs 4 and 5
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
I was hinted to used two for loops and this is what I have thus far, what I can't figure out is how to display it like the example.
#include <iostream>
using namespace std;
int main() {
int num1;
int num2;
cout << "Enter two numbers between 2 and 10." << endl;
[Code] .....
View 2 Replies
View Related
Oct 22, 2012
I am attempting to write a simple C program, in which the user is asked to input their name and height in inches and the output is the user's height in centimeters.
I have attached my program and what happens when I try to run it.
Attached Images : PM.jpg (120.6 KB)
View 1 Replies
View Related
Oct 23, 2014
How can I check for an invalid date when I run the program? I am trying to enter a conditional statement that checks for a valid or invalid date.
Programing Question: Write a program that inputs a date (e.g., July 4, 2008) and outputs the day of the week that corresponds to that date. Here is what I Have. The program runs. I need it to loop around.
#include <iostream>
using namespace std;
const int JANUARY = 1;
const int FEBRUARY = 2;
const int MARCH = 3;
const int APRIL = 4;
[Code] ....
View 1 Replies
View Related
Nov 25, 2014
The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.
Here's my code:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);
[Code] ....
And I'm getting the error:
freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’
I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.
View 4 Replies
View Related
Nov 24, 2014
I have trouble printing out the movies starting with inputing only two letters.
#include <iostream> //cout, cin, endl,getline
#include <fstream> //ifstream
#include <cstdlib> // exit
using namespace std;
const int NUM_MOVIES = 116792;
struct Movie {
[Code] ....
View 1 Replies
View Related
Apr 20, 2014
I'm writing the program below to take an integer input for temperature and display a cheesy message for different ranges for each day of the week.
I tried using two if statements, the first to determine if the input is valid, and the else display that it was invalid and to try again.
The second set of if (if else) statements would evaluate a number input and display the cheesy message based on the value, or if it was out of range, to make you re input that days temperature.
I understand that the else statement is linked to the closest if statement, unless brackets are added to prevent this. I thought my brackets were correct, but I keep getting [Error]'else' without previous if'. The red lines are the if and else statement I'd like to be linked, and tried to do so by enclosing the 2nd if statement in brackets.
The assignment doesn't require the error checking, but if I don't use some form of it I believe it will just loop. Again I have to use the last 4 lines due to instructors rules, and have to use scanf and not strings or arrays.
This program will ask the user what the temperature will be for each day of the week. The integer input from the keyboard will be tested in a series of IF tests and a message will be printed depending on the temperature.
Code] ....
#include <stdio.h>
#define MAX 100
#define MIN 0
int main() {
int day = 1;
int temp;
[Code] ....
View 10 Replies
View Related
Oct 25, 2014
My program is supposed to get ask the user a date (MM DD YYYY) and its supposed to tell them what day of the week that specific date is. Well, I was told to check for leap years, and if the Feb 29 is a non-leap year, its supposed to cout an invalid statement and tells the user to try again. My problem is that its not looping through only when its Feb 29 2015 for example.I have been trying to find a solution and I cant find one so far? Like, I said, it works for other dates, just not checking and looping Feb 29 2014 or 2015, etc?
#include <iostream>
using namespace std;
const int JANUARY = 1;
const int FEBRUARY = 2;
const int MARCH = 3;
[code].....
View 2 Replies
View Related
Feb 29, 2012
im trying to write a program that prompts the user to enter three numbers and then prints them vertically (each on one line), first forward and then reversed. this is how the design should look:
enter three numbers: 1 43 54
your numbers fowards:
1
43
54
your numbers backwards:
54
43
1
this is what i have thus far when it comes to code....
#include <stdio>
int main (void) {
// local declarations
int a;
int b;
int c
[code].....
View 1 Replies
View Related
Feb 10, 2015
I am in a computer science class at LSU and i can not figure out how to writhe this program. The program must let the user input (MM/DD/YYYY) and then output what day that date was on and also if it was a leap year or not.
View 1 Replies
View Related
Feb 7, 2015
I need to write a program that tells the day of the week, month, day, year, and whether it is a leap year or not from a input of MM DD YYYY form.
Example: Enter numeric values for month, day and year of a date> 10 31 1990 Wednesday, October 31, 1990 occurred in a non-leap year.
View 3 Replies
View Related
May 1, 2014
How to do the problem below using loop?
Input numbers until the user types a 0, then output the product of the non 0 numbers: e
E.g., if the user types 2 4 6 0, the program should output 48
View 3 Replies
View Related
Apr 27, 2013
In my class we were supposed to write a program from the book that inputted the names and votes and the program is supposed to spit out who won the vote. I did this then while i was reading the assignment from the instructor I noticed he wanted the information inputted from a TXT file instead of manually inputting it. I cannot seem to get it to work....
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#define N 5
char names[N][20];
float votes[N];
[Code] ....
here is the txt file
Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Ashtony 1800
View 2 Replies
View Related
Aug 15, 2013
Write the definition of the class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sunday for Sunday. The program should be able to perform the following operations on an object of type dayType:
a. Set the day
b. Print the day
c. Return the day
d. Return the next day
e. Return the previous day
f. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
g. Add the appropriate constructors
Write the definitions of the functions to implement the operations for the class dayType.
My code:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string my_Day[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
class dayType
[Code] .....
And here are the error messages that I get:
Line 23 error: prototype for 'void dayType::setDay(int)' does not match any in class 'dayType'
Line 11 error: candidate is: void dayType::setDay()
Line 36 error: prototype for 'void dayType::getDay(int) const' does not match any in class 'dayType'
Line 13 error: candidate is: void dayType::getDay()
I know this is probably a really easy mistake but I am new to Programming and I have changed this code for days to no avail.
View 2 Replies
View Related
Mar 2, 2014
// this program gives random number output
#include <iostream>
#include <cstdlib>// contains function protype for rand
#include <iomanip>// for setw
using namespace std;
[code]....
what is the effect on output of program of different numbers input to the int data type named seed*/
View 1 Replies
View Related
Dec 8, 2013
I need the program to do a calculation after the user inputs 10 numbers . This is what I have tried so far:
int count;
float value, high,low, sum,average;
sum=0;
count=0;
input:
printf("Enter a number (enter negative value to finish program):
");
scanf_s("%f",&value);
[Code] ....
output:
average=sum/count;
if(count==10) {
printf("total values :%d
",count);
printf("The Highest value :%f
Lowest Value: %f
",high,low);
printf("The average of the values is:%f
",average);
}
View 3 Replies
View Related
Dec 8, 2013
I built a program that accepts two input from the user, using a array inside a loop, it is pass to a function inside a class which will display the two number, the problem is when the user is inputting a number and it is 1 the program continuously as the user to input a number, and when 2 is entered the program ask another number and end, but for example you entered 2 and 3. . . it will then outpu 2 and 4 (so 3 + 1 ) and always the last number is plus one. here is the code.
main.cpp
#include <iostream>
#include "newclass.h"
using namespace std;
[Code].....
View 5 Replies
View Related
Feb 23, 2015
So we have a weekend assignment that is "Write a c++ program that will allow a user to input their first name into a string, and use the switch/case statement to produce the following output. Your Program should prompt the use rwith the numbers and the options for each (school, classification, and mood) allowing them to make a choice"
My issue is with the output. The output at the end is the number that they input and not the name of the case they chose, so if they chose option 1 for school it does not print out "BRCC" at the end for the output it prints a 1.
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string name;
cout << "Please enter your name: ";
cin >> name;
[code].....
View 7 Replies
View Related
Oct 28, 2013
I need a program to run that will accept an input for user id. It will take the customer input and capitalize the letters, and return invalid id with the user inputted values. Then if it's valid it will add a counter counting the number of letters and numbers. It will keep track until the user puts in !. It seems when I try to pass values from the array to my toUpper function to capitalize it it doesn't seem to work right.
View 3 Replies
View Related