0
[SOLVED]What all did I do wrong?
I am trying to create a program that will tell you what grade you should be in based on how old you are. I am very new at C++ and was hopeing for some clarification on what I may have ddone wrong for my code to keep giving errors. https://code.sololearn.com/cLEyR7Inq01H/#
5 Respuestas
+ 3
#include <iostream>
#include <string>
using namespace std;
void gradL(int age) //Takes your age and calculates your school grade.
{
if (age < 5 && age >= 0 )
{
cout << "Too Young For School " << endl;
}
else if (age == 5)
{
cout << "Go To Kindergarten." << endl;
}
else if (age >= 6 && age <= 17)
{
cout << "Go To Grade "<<endl;
}
else if (age > 17)
{
cout << "Go To College." << endl;
}
else if (age < 0) // If you end up putting a negative number.
{
cout << "Something Went Wrong!!!" << endl;
}
}
int main()
{
cout << "Please Enter Your Age." << endl;
int age;
cin >> age;//Takes your input here.
gradL(age);
return 0;
}
+ 1
Pls use () and {} in if statements. And use && instead of &.
&& - means "and"
& - is a memory reference
== - means equal
= - variable takes value
return void?
return is used only if the function is not void.
+ 1
In c++, the condition after if must be surrounded by a pair of parentheses. I think you are mixing c++ and python up.
+ 1
Thank you guys so much
+ 1
Now I'm getting a compiation error, even if I take out the section getline(age); int grade = age - 5, and the cout for grade
#include <iostream>
#include <string>
using namespace std;
//This is supposed to assign you a grade for school.
void gradL(int age)
{//Takes your age and calculates your school grade.
if (age < 5 && age > 0)
{
cout << "Too Young For School " << endl;
}
else if (age == 5)
{
cout << "Go To Kindergarten." << endl;
}
else if (age >= 6 && age <= 17)
{
getline(age);
int grade = age - 5;
cout << "Go To Grade " << grade << endl;
}
else if (age > 17)
{
cout << "Go To College." << endl;
}
else
{// If you end up putting a negative number.
cout << "Something Went Wrong!!!" << endl;
}
}
int main()
{
cout << "Please Enter Your Age." << endl;
int age;
cin >> age;//Takes your input here.
gradL(age);
return 0;
}