(c++)- error
=================== MISMATCH FOUND ON LINE 0007: ===================
ACTUAL : 2~year
EXPECTED: 2~years
======================================================
#include <iostream>
using namespace std;
int main()
{
int daynum, n;
cout<<"Please enter a day of the year (0 to exit): ";
cin>>daynum;
cout<<daynum<<endl;
while(daynum>0)
{
L:if(daynum>1&&daynum<=31)
cout<<"jan "<<daynum<<endl;
else if(daynum>31&&daynum<=59)
{
cout<<"feb "<<daynum-31<<endl;
}
else if(daynum>59&&daynum<=90)
{
cout<<"mar "<<daynum-59<<endl;
}
else if(daynum>90&&daynum<=120)
{
cout<<"apr "<<daynum-90<<endl;
}
else if(daynum>120&&daynum<=151)
{
cout<<"may "<<daynum-120<<endl;
}
else if(daynum>151&&daynum<=181)
{
cout<<"jun "<<daynum-151<<endl;
}
else if(daynum>181&&daynum<=212)
{
cout<<"jul "<<daynum-181<<endl;
}
else if(daynum>212&&daynum<=243)
{
cout<<"aug "<<daynum-212<<endl;
}
else if(daynum>243&&daynum<=273)
{
cout<<"sep "<<daynum-243<<endl;
}
else if(daynum>273&&daynum<=304)
{
cout<<"oct "<<daynum-273<<endl;
}
else if(daynum>304&&daynum<=334)
{
cout<<"nov "<<daynum-304<<endl;
}
else if(daynum>334&&daynum<=365)
{
cout<<"dec "<<daynum-334<<endl;
}
else if(daynum>365)
{
n=daynum/365;
cout<<n<<" year"<<endl;
daynum=daynum-(365*n);
goto L;
}
cout<<"Please enter a day of the year (0 to exit): ";
cin>>daynum;
cout<<daynum<<endl;
}
if(daynum==0)
cout<<"Thanks for playing!";
if(daynum<0)
cout<<"Invalid input!";
return 0;
}
INSTRUCTIONS:
Given a number, calculate how many years into the future it is, and what date. Assume no leap years. For example: Please enter a day of the year (0 to exit): 1 jan 1 Please enter a day of the year (0 to exit): 365 dec 31 Please enter a day of the year (0 to exit): 366 1 year jan 1 Please enter a day of the year (0 to exit): 0 Thanks for playing!
#include <iostream>
#include <string>
using namespace std;
int main() {
const int MonthDays[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const string MonthName[] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
int day, year=0, index;
while(1){
cin>>day;
cout<<endl;
if(day==0){
break;
}
index = 0;
year = 0;
while(day > 365) {
day = day - 365;
year++;
}
if(year == 1) {
cout<<year<<" Year"<<endl;
} else if(year > 1) {
cout<<year<<" Years"<<endl;
}
index = 0;
while(day > MonthDays[index]) {
day = day - MonthDays[index];
index++;
}
cout << MonthName[index] << " " << day << endl;
}
cout<<"Thanks for playing!";
return 0;
}
I have shortened the above code, Since goto statements and lot of if-else statements are not a good way of writing the code.. they are deemed as bad practices.. let me know if any issues with this code.
(c++)- error =================== MISMATCH FOUND ON LINE 0007: =================== ACTUAL 
Given a number, calculate how many years into the future it is, and what date. Assume no leap years. For example: Please enter a day of the year (0 to exit): 1 jan 1 Please enter a day of the year (0 to exit): 365 dec 31 Please enter a day of the year (0 to exit): 366 1 year jan 1 Please enter a day of the year (0 to exit): 0 Thanks for playing! My current code: #include...
Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example, Day 2 would be January 2. Day 32 would be February 1. Day 365 would be December 31. The constructor for the class should take as parameter an integer representing the day of the year, and the class should have...
Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() { int n; double avg, sum = 0;; string in_file, out_file; cout << "Please enter the name of the input file: "; cin >> in_file; ...
My if/else statement wont run the program that I am calling. The menu prints but once I select a number the menu just reprints, the function called wont run. What can I do to fix this probelm? #include <iostream> #include "miltime.h" #include "time.h" #include "productionworker.h" #include "employee.h" #include "numdays.h" #include "circle.h" using namespace std; int main() { int select=1; while (select>0) { cout << "Option 1:Circle Class\n"<< endl; cout << "Option 2:NumDay Class\n" << endl; cout <<"Option 3:Employee and Production...
-can you change the program that I attached to make 3 file
songmain.cpp , song.cpp , and song.h
-I attached my program and the example out put.
-Must use Cstring not string
-Use strcpy
- use strcpy when you use Cstring: instead of this->name=name
.... use strcpy ( this->name, name)
- the readdata, printalltasks, printtasksindaterange,
complitetasks, addtasks must be in the Taskmain.cpp
- I also attached some requirements below as a picture
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
Why is this not giving me a letter grade when run? #include <iostream> #include <iomanip> using namespace std; int main() { double grade1, grade2, grade3, grade4, total; cout << "please enter the first grade : "; cin >> grade1; cout << "Please enter the second grade : "; cin >> grade2; cout << "Please enter the third grade : "; cin >> grade3; cout << "Please enter the fourth grade : "; cin >> grade4; total = (grade1 + grade2...
Trying to figure out how to complete my fourth case 4 (option exit), write a function that display a “Good Bye” message and exits/log out from user’s account displaying a menu (sign in, balance, withdraw and exit.. #include<iostream> #include <limits> using namespace std; void printstar(char ch , int n); double balance1; int main() { system("color A0"); cout<<"\n\t\t ========================================="<< endl; cout<<"\t\t || VASQUEZ ATM SERVICES ||"<< endl; cout<<"\t\t ========================================\n\n"<< endl; int password; int pincode ; cout<<" USERS \n"; cout<<" [1] -...
Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) { // average function , declaring variable int i; char str[40]; float avg = 0; // iterating in...
What does this error message mean? "expected primary expression before int" Also, how do i get the program to repeat the numbers that were entered by the user back to me? this is my code below: // This program accepts a series of positive numbers // This code was last modified on 2/16/2020 #include <iostream> #include <iomanip> #include <cmath> using namespace std; void welcome(); int entrySubmission(int numbers); void acceptsNumbers(int); void goodbye(); int main() { welcome(); entrySubmission(int numbers); acceptsNumbers(int); goodbye(); return...