Hi, so i was practicing c++ variables and switch statements today and I was almost positive I did this correctly. However, when i try to write in a 'case' for my switch statement, it said I used too many characters. You can clearly see that I entered how many characters it can hold in the code. Now i'm stumped, any help? (I used visual studio if that helps) Here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <conio.h>
usingnamespace std;
int main()
{
char soda [30];
cout << "enter what soda you want. We got sprite, fanta, coca cola, sams cola, and root beer." << endl;
cin >> soda;
switch (soda [30])
case'sprite':
cout << "here's your sprite" << endl;
getch();
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int soda = 0;
int sprite = 0;
int fanta = 0;
cout << "Enter what soda you want. We got sprite, fanta, coca cola,\n";
cout << "sams cola, and root beer." << endl;
cin >> soda;
cout << endl;
{
if ( soda == sprite )
cout << "Here's your Sprite";
else;
if ( soda == fanta )
cout << "Here's your Fanta";
}
return 0;
}