### Help with a switch statement

Hi I recently wrote a code that determines average and gives a letter grade using if else statements and now I need to change it to a switch statement but have no idea how to do it. The code works fine its just now I need the if else to be a switch statement.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````//This program will prompt the user for 5 numbers and output the average of these numbers //and a letter grade #include #include using namespace std; int main() { int avg=0; int sum=0; int num1=0; int num2=0; int num3=0; int num4=0; int num5=0; char letter; letter='A'; letter='B'; letter='C'; letter='D'; letter='F'; string firstname; //Prompt for 5 numbers and your name cout << "Please input your name\n" << endl; cin >> firstname; cout << "Okay "<< firstname <<" please input five numbers each separated by a space: \n"; cin >> num1 >> num2 >> num3 >> num4 >> num5; //Calculate the average sum = num1+num2+num3+num4+num5; avg=sum/5; cout << "These are the numbers: " << num1 << "," << num2 << "," << num3 << "," << num4 << "," << num5 << endl; cout << "This is the sum: " << num1+num2+num3+num4+num5 << endl; cout << "This is the average: " <=90) letter = ('A'); else if(avg>=80) letter = ('B'); else if(avg>=70) letter = ('C'); else if(avg>=60) letter = ('D'); else if (avg<60) letter = ('F'); else cout << "There is an error"; cout << "This is the letter grade: " << letter << endl; system ("pause"); return 0; }``````
 ``12345678910111213`` ``````switch (avg/10) // integer division will give us a number from 0 - 10 { case 9: case 10: letter = 'A'; break; case 8: letter = 'B'; break; case 7: letter = 'C'; break; case 6: letter = 'D'; break; default: letter = 'F'; }``````

Topic archived. No new replies allowed.