C :: Take Integer Input For Temperature And Display Message For Different Ranges For Each Day Of Week
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
ADVERTISEMENT
Nov 8, 2013
I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:
cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {
[Code] ....
I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.
View 8 Replies
View Related
Feb 12, 2015
Write a program that creates and displays a table of temperature conversions. Get the starting temperature from the keyboard in degrees Celsius (do not allow input of a value below absolute zero). Also get an integer value to represent the number of degrees to increment for each of a 20 row table (do not allow the increment value to be less than one. The first column will be a row number starting with one, follow by the Celsius value and then the conversions into Fahrenheit, Kelvin, and Rankine. Be sure that all columns are neatly right aligned for a variety of inputs.
Thats what i wrote so far:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double C,F,K,R,n,a;
cout <<"Enter starting temperature in Celsius: ";
cin >> C;
[Code] ....
Thats what the instructor looking for:
Enter starting temperature in Celsius: -500
ERROR: Temp must be >= -273.15: -273.15
Enter increments in degrees Celsius: 100
# Cels Fahr Kelv Rank
1 -273.15 -459.67 0.00 0.00
2 -173.15 -279.67 100.00 180.00
3 -73.15 -99.67 200.00 360.00
4 26.85 80.33 300.00 540.00
5 126.85 260.33 400.00 720.00
6 226.85 440.33 500.00 900.00
7 326.85 620.33 600.00 1080.00
8 426.85 800.33 700.00 1260.00
9 526.85 980.33 800.00 1440.00
10 626.85 1160.33 900.00 1620.00
11 726.85 1340.33 1000.00 1800.00
12 826.85 1520.33 1100.00 1980.00
13 926.85 1700.33 1200.00 2160.00
14 1026.85 1880.33 1300.00 2340.00
15 1126.85 2060.33 1400.00 2520.00
16 1226.85 2240.33 1500.00 2700.00
17 1326.85 2420.33 1600.00 2880.00
18 1426.85 2600.33 1700.00 3060.00
19 1526.85 2780.33 1800.00 3240.00
20 1626.85 2960.33 1900.00 3420.00
Press any key to continue . . .
My question is to know how to make the sequence from 1 to 20 and whats the best statement for increment...
View 2 Replies
View Related
Feb 12, 2013
I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two separate vectors. After an unknown amount of data has been entered, and the end-of-file has been reached, I have to display the highest temperature and the time(s) it occured (bear in mind that the highest temperature may be recorded more than once). The output of that part should be as follows:
Highest temperature: 51
Recorded at time(s):
22:45
2:27
Something like that. The time should also be converted to hours and minutes. To the point: I've done some research on bubble sorting, but they only use it for arrays.
View 3 Replies
View Related
Jan 16, 2013
I have to write a program for a restaurant and their food has to be cooked on a hot sheet of metal and too cook their burgers properly I must keep a maintain temp of 400 F, for the grill and to measure the temperature using a probe at 12 points, there are 3 elements with 3 points on them
View 2 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
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
Feb 1, 2015
How would you be able to show both outputs celsius and Fahrenheit and my temperature conversion is coming up wrong when i enter in the input. here is my code...
#include<iostream>
using namespace std;
int main(){
double celsius;
double fahrenheit;
[code].....
View 1 Replies
View Related
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
View Related
Dec 9, 2014
I was wondering if it's possible to display output message without using console.write or any console function
View 7 Replies
View Related
Jul 25, 2012
How to display a message only for 10s using timer in c ....
View 1 Replies
View Related
Jul 13, 2014
I'm currently making a math program in c++ windows form application. I'm trying to make it so where the user presses the number button I such as 1 button to display a 1 in my textbox.
Code:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
View 1 Replies
View Related
Oct 11, 2012
i'm making a program that, given a person's birthdate or any other date, will display the day of the week of the person was born.
There is this part where it says "use a switch statement to make this calculation, If desired month is 12, add the number of days for November, if desired month is 11 add the number of days for october....
So it's suppose to start with "case 12 :...
I can't figure out what to write for the statement....
View 6 Replies
View Related
Feb 21, 2014
Is it possible to display a message at the bottom of a dialog box shown in the attachment? If so, how?
View 5 Replies
View Related
May 28, 2014
is it possible to take integer or char data type on message box to V C++?
View 2 Replies
View Related
Dec 24, 2014
I'm trying to compare two float ranges and it seems to be a hit and miss. I'm trying to use a object origin and dimensions comparing it to another set for collisions.
View 12 Replies
View Related
Apr 25, 2014
I made this pthread/mutex program that makes deposits and withdrawals of random amounts. I have it working how I wish, however, I cannot figure out how to make it so that the random values are only within certain ranges. For example, let's just say I want all deposits to be random doubles between 50.00 to 100.00 and withdrawals between 25.00 to 50.00, or something similar.
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
[Code].....
View 3 Replies
View Related
May 14, 2013
I am trying to get this simple validation loop to work so that it only displays the error message when the input is outside the range 1-3. yet it always seems to display the message.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int Menu ();
int ValidInt(int , int );
[Code] ....
View 5 Replies
View Related
Mar 4, 2014
A problem that lets the user enter any positive integer, but you do not have to check for this, and then calculates the sum of the digits and displays this to user. For example, if user enters 14503, the outputted sum of the digits would be 13.
Here is my program
#include <iostream>
int main(void) {
int integer, sum=0;
while(integer) {
sum += integer % 10;
integer /= 10;
} cout << "The sum of the integers numbers is " <<sum;
return 0;
}
View 5 Replies
View Related
Dec 28, 2013
Constructing this right aligned half pyramid? The code I had so far is right aligned and they're not in numbers
Write a program that receives one positive integer and display
_________ _ 1
________ 4 2
_______9 6 3
___16 12 8 4
25 20 15 10 5
when the user key in 5.PS: ignore the line
View 3 Replies
View Related
Apr 24, 2014
I'm new to C programming and in my first computer science class. Our assignment was to write a program that displays each digit of an integer in English. I wrote the following but cannot figure out why it won't display zeros. When I execute and type in the number 1,000, I get "zero."
Code:
#include <stdio.h>
int main (void)
{
int x, y = 0;
printf ("This program displays each digit of an integer in English.
[Code] ....
View 5 Replies
View Related
Oct 20, 2014
i wanna put an integer into a string for example:
Code:
string name;
int num=8;
name= "George"
//
I want in the end of George to pas the num variable i ve seen some examples but ive not yet come up with a solution like str.insert();
View 7 Replies
View Related
Jan 15, 2013
I have an assignment to do..i have done it..but i need to do one more thing. Things sound like this: user inputs 6 integers program needs to check them if there are integer if not it has to output a message for the user if the input is integer it has to go further and work with the input. I have used this structure :
if ( ! ( cin >> temp ) ) {
cout<<"Input is not integer.This program will end ! "<<endl<<endl<<endl;
system("pause");
return 0;
}
Where I declared temp as being int since i started, the problem is after it gets the last input still waits for an input i will attach the source code if needed.
View 3 Replies
View Related
May 17, 2014
The code is supposed to display the total and averages of the data as well, but cuts off due to an error in the code.
Since this code is quite lengthy, I will be breaking it up into two posts.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
[Code].....
View 6 Replies
View Related
Aug 14, 2013
Code:
Prompt the user to input a string,
and then output the sum of all the digits in the string.
Sample Run 1:
Input -> A111B222C
output -> 9
Sample Run 2:
Input -> ABC123XYZ32100000005555555555zzzzzz
output -> 62
View 1 Replies
View Related
Nov 3, 2013
I have a homework that needs to verify if the input of the user is an integer using only loops no if statements Here's the problem:
A program is required that prompts the user for a number. The program will then print a series of asterisks to represent the number. If the user enters a number less than 1, the program stops. For example:
Enter a number: 5
*****
Enter a number: 3
***
Enter a number: 9
*********
Enter a number: 0
All user input must be validated:
- Check for non-numeric input when reading numeric input
- Check that values entered are within the expected range for their purpose, or in range based on the requirements statement
View 10 Replies
View Related