is it codeblocks that doesnt like string? cant debug my code untill i know its not a compiler bug

So i finished studying buckys awsome youtube classes, ive understood the entire
dev hq tutorial as much as i can without practicing my own code, so i found a really good beginner challenge on this forum to do such practising;

i have to get the computer to ask how many pancakes each person had and then work out who ate the most, i can tell that im not supposed to be repeating myself and im sure theres a more efficient way to do this (thank god for copy and paste, although again i can tell its not wise to rely on) but i decided it was time to move from dev and on to codeblocks...and its tottaly not reconising string, im not sure if its me or the compiler but being a n00b im sure its me, thank god for this site...

please dont give too much away i ned practice but dont keep to much either must learn ^_^






#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;

class fatty {
public:
void getcake ()
{
cout << "the fat bastard called "<< name << "ate the most pancakes " << endl;
int pancakes;
string name;
};


int main()

{

fatty fat1;
fat1.name = "bubba";
fatty fat2;
fat2.name = "cartman";
fatty fat3;
fat3.name = "elvis";
fatty fat4;
fat4.name = "santa";
fatty fat5;
fat5.name = "yo momma";
fatty fat6;
fat6.name = "kublah kahn";
fatty fat7;
fat7.name = "mr creosate";
fatty fat8;
fat8.name = "doctor lipo";


cout << "how many pancakes did " << fat1.name << " have?" << endl;
cin >> pancakes;
cout << "how many pancakes did " << fat2.name << " have?" << endl;
cin >> pancakes;
cout << "how many pancakes did " << fat3.name << " have?" << endl;
cin >> pancakes;
cout << "how many pancakes did " << fat4.name << " have?" << endl;
cin >> pancakes;
cout << "how many pancakes did " << fat5.name << " have?" << endl;
cin >> pancakes;
cout << "how many pancakes did " << fat6.name << " have?" << endl;
cin >> pancakes;
cout << "how many pancakes did " << fat7.name << " have?" << endl;
cin >> pancakes;
cout << "how many pancakes did " << fat8.name << " have?" << endl;
cin >> pancakes;

switch (pancakes)
{
case fat1.pancakes > fat2.pancakes, fat3.pancakes,fat4.pancakes,fat5.pancakes,fat6.pancakes,fat7.pancakes,fat8.pancakes:
fat1.getcake;
break;
case fat2.pancakes > fat1.pancakes, fat3.pancakes,fat4.pancakes,fat5.pancakes,fat6.pancakes,fat7.pancakes,fat8.pancakes:
fat2.getcake;
break;
case fat3.pancakes > fat1.pancakes, fat2.pancakes,fat4.pancakes,fat5.pancakes,fat6.pancakes,fat7.pancakes,fat8.pancakes:
fat3.getcake;
break;
case fat4.pancakes > fat1.pancakes, fat2.pancakes,fat3.pancakes,fat5.pancakes,fat6.pancakes,fat7.pancakes,fat8.pancakes:
fat4.getcake;
break;
case fat5.pancakes > fat1.pancakes, fat2.pancakes,fat3.pancakes,fat4.pancakes,fat6.pancakes,fat7.pancakes,fat8.pancakes:
fat5.getcake;
break;
case fat6.pancakes > fat1.pancakes, fat2.pancakes,fat3.pancakes,fat4.pancakes,fat5.pancakes,fat7.pancakes,fat8.pancakes:
fat6.getcake;
break;
case fat7.pancakes > fat1.pancakes, fat2.pancakes,fat3.pancakes,fat4.pancakes,fat5.pancakes,fat6.pancakes,fat8.pancakes:
fat7.getcake;
break;
case fat8.pancakes > fat1.pancakes, fat2.pancakes,fat3.pancakes,fat4.pancakes,fat5.pancakes,fat6.pancakes,fat7.pancakes:
fat8.getcake;
break;
}




return 0;

}
It's not a compiler bug. There are many problems with the code. One problem is that you forgot to put an end to the getcake function.
Last edited on
ahh, still i fiddled withit too much...how would i use switch better than this???
Last edited on
It's not a compiler bug. That's generally the last place to look for problems.

There's plenty in your code that the compiler might give messages about, but that's because the code needs some work.

Here's a start:

1
2
3
4
5
6
7
8
9
10
11
12
class fatty {

public:

    string name;
   int pancakes;

    void getcake ()
    {
        cout << "the fatty called "<< name << "ate the most pancakes " << endl;
    }
};


There was (at least) a closing brace } missing.

Further down, the switch statement looks deeply flawed. I suggest you may want to re-think that section and come up with an alternative solution.
Last edited on
Topic archived. No new replies allowed.