私たちの任務は、forループプログラムとwhileループプログラムをswitch文のプログラムから外すことです。なぜ私のforループプログラムが動作していないのかを知る必要があります。すばらしいです。なぜ私の閏年プログラムのforループが機能していないのですか?
whileループ:ループの
/*
* File: main.cpp
* Author: Jorge Elias
*
* Created on October 22, 2017, 11:53 PM
*/
#include<cstdlib>
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
/*
*
*/
int main() {
//Assigning the Integers
int month,days,year;
//Asking User for inputs
cout<<"Please enter the Year: ";cin>>year;
cout<<"Please enter the month (1-12): ";cin>>month;
//Switch statement to determine how many days there are in a month
switch(month) {
case 1:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 10:
case 12:
cout<<"31 days"<<endl;
break;
case 9:
case 11:
cout<<"30 days"<<endl;
break;
while(month<0){
cout<<"INVALID INPUT! Please enter month number between 1-12"<<endl;
break;
}
//Determine if the Year inputed by the User is a Leap Year or not
case 2:
while(year>0){
if(year % 100 == 0 && year % 400 == 0)
{
cout<<"This is a leap year, 29 days"<<endl;
}
else if(year % 100 !=0 && year % 4 == 0)
{
cout<<"This is a leap year, 29 days"<<endl;
}
else
cout<<"there are 28 days";
break;
}
}
return 0;
}
: * *ファイル:main.cppに *著者:ホルヘ・エリアス * * 2017年10月22日に作成され、午前11時53分PM */
#include<cstdlib>
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
/*
*
*/
int main() {
//Assigning the Integers
int month,days,year;
//Asking User for inputs
cout<<"Please enter the Year: ";cin>>year;
cout<<"Please enter the month (1-12): ";cin>>month;
//Switch statement to determine how many days there are in a month
for(month>1; month<12;){
switch(month) {
case 1:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 10:
case 12:
cout<<"31 days"<<endl;
break;
case 9:
case 11:
cout<<"30 days"<<endl;
break;
for(month<1;month>12;){
cout<<"INVALID INPUT! Please enter month number between 1-12"<<endl;
break;
}
//Determine if the Year inputed by the User is a Leap Year or not
case 2:
for(year % 100 == 0;year % 400 == 0;)
{
cout<<"This is a leap year, 29 days"<<endl;
for(year % 100 !=0; year % 4 == 0;)
{
cout<<"This is a leap year, 29 days"<<endl;
}
for(year >0;)
{
cout<<"there are 28 days";
break;
}
}
}
}
return 0;
}
に結果の
例
現在の失敗振る舞いを記述してください。 – Aaron
それは私に括弧の前に一次式が必要だと言うエラーメッセージを与える – JE3
とその行はどのような行にはエラーがあります – pm100